Redux - Remove an Item from an Array

Goodmorning, quick question what is the underscore for or represent in solution number 2 //// return state.filter((_, index)
Your code so far

const immutableReducer = (state = [0,1,2,3,4,5], action) => {
  switch(action.type) {
    case 'REMOVE_ITEM':
      // Don't mutate state here or the tests will fail
      return
    default:
      return state;
  }
};

const removeItem = (index) => {
  return {
    type: 'REMOVE_ITEM',
    index
  }
}

const store = Redux.createStore(immutableReducer);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54

Challenge: Redux - Remove an Item from an Array

Link to the challenge:

It is just a naming convention for unused parameters.

The filter method isn’t using the element parameter, only the index, but you have to have the element parameter to get the index parameter (you can’t skip a parameter).

const numbers = [1, 2, 3, 4, 5];

const evenIndex = numbers.filter((_, index) => index % 2 === 0);
console.log(evenIndex); // [1, 3, 5]

Thank you for including an example as well :slight_smile: much appreciated