Almog Koren Almog Koren - 3 years ago 311
React JSX Question

Redux remove item from state based on object value

I have the following state in my redux store, it's photos which has an array of objects
enter image description here

Each object is different, I need to be able to find the object with the filename and remove the entire array item I have tried with index and the following but not really working

case actionTypes.PHOTO_DELETE:
// return state.filter((photo) => photo.filename !==

return { photos: =>
photo.filename !==

// let index = => photo.fillname ===;
var index = _.findIndex(, function(photos) {
return ==
//return update(state, {photoGroups: {$splice: [[index]]}});

Answer Source

Filter the photos array by checking if the object with specified filename does not exist in the inner array. If it doesn't then findIndex() === -1.

return {
  photos: =>
    photo.findIndex(object => object.filename === === -1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download