I am currently working with an array that contains 146 objects, each object having its own unique id. My goal is to delete any objects from the array that do not have a matching id. I wrote a function to accomplish this task, however, it only works for half of the array. The function was functioning correctly before I implemented the splice method. Here is my code:
getFullData(){
var fullData = [OBJECTS].sort(function(a,b){if(a.date<b.date)return 1; if(a.date > b.date) return -1})} //sorting
fullData.map(val=>{
Object.assign(val, {dataType:this.getDateType(val.date)}); //this line not about these problem
if (val.device !== this.id) {
fullData.splice(fullData.indexOf(val), 1);
}
});
return fullData;
}
All ids on the objects are currently the same. If I route a different id using the router, all objects should be deleted, but only 73 are being removed.