so I created an array with several objects inside it
const students = [
{jean:14},
{mike:19},
{nean:16},
{annie:17}
]
and I want to remove certain object from the array by using the object's index
let index = students.findIndex(i => {
if (Object.keys(i) == 'nean'){
return true
}
})
and it returns the index of the object that I want to remove from the array and I do .splice() to remove it from the array. It does remove the object that I expect to be removed but it also removes the item after it
students.splice(index, index)
console.log(students)
//(2) […] 0: Object { jean: 14 } 1: Object { mike: 19 } length: 2
students.splice(index, 1)array.filter()is your friendif()doesn't really make sense. Neither does using unique keys in each object. Much simpler with structure like[{name:'jean', age:14},{name:'mike'...}]