DEV Community

Discussion on: How to remove a specific item from an array

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

IndexOf and splice will not work with objects. For this you can use Array::findIndex

let arr = [{x: 10}, {x: 20}, {x: 30}]
let index = arr.findIndex(item => item.x == 20);
arr.splice(index, 1);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
smpnjn profile image
Johnny Simpson

true good point.