I have an array of integers, and I'm using the .push() method to add elements to it.
Why do I not delete the specified elements from the array when I use splice ()?
var arr = [1001, 1002, 1005, 1006];
var list = [{"id": 1002},{"id": 1005},{"id": 1006},{"id": 1007},{"id": 1008},{"id": 1009},{"id": 1010}];
function inArray(value, arr){
for (let item in arr) {
if (list.hasOwnProperty(item)) {
if (arr[item] === value) {
return true;
}
}
}
return false;
};
for (let item in list) {
if (list.hasOwnProperty(item)) {
if (inArray(list[item].id, arr)) {
list.splice(item, 1);
}
}
};
console.log(list);