Redux Remove an Item from an Array

Tell us what’s happening:
I feel like using splice instead of slice would also do the job. Why is this incorrect?

  **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 [...state].splice(action.index,1)
  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 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0

Challenge: Remove an Item from an Array

Link to the challenge:

Look at the docs for the splice method return value.

1 Like

I had this same question. Thanks! Didn’t realize it only returned the missing subset. I guess that makes sense since it’s modifying the array in place.