React redux succinct way to remove object from array if match certain criteria and without mutating array
I have an array that contains a number of objects.
I am wondering what is the cleanest way to remove the items from the array if they match a certain criteria, while also preventing the mutation of the state as I am using redux.
The code below should work, but I am sure there must be a more succinct way, while also preventing the array being mutated.
state = [
{
name: 'larry',
age 25
},
{
name: 'zach',
age: 20
},
{
name: 'chuck',
age: 17 {
name: 'zach',
age: 20
}
]
Redux reducer
case 'REMOVE_LOGIN_ERROR_CONSOLE_MESSAGE':
for (var i = 0; i < state.length; i++) {
if (state[i].name = 'zach') {
delete state[i];
}
}
return [...state];
As I am using redux, I also want to avoid mutating the array.