What is the cleanest way to remove an element from an immutable array in JS? [duplicate]
问题 This question already has answers here : Is this the correct way to delete an item using redux? (4 answers) Closed 2 years ago . I need to remove an element from an array that is a state of a React Component. Which means that it is an immutable object. Adding a element is easy using spread syntax. return { ...state, locations: [...state.locations, {}] }; Removing is a little more tricky. I need to use an intermediate object. var l = [...state.locations] l.splice(index, 1) return { ...state,