I encountered an issue while trying to filter an array using a specific method. However, I noticed that one value is being skipped in the process!
function customFilterArray(array, remove){
console.log('Length of Array:',array.length)
console.log("Array:",array);
console.log('Values to Remove:',remove);
console.log('------');
array.forEach(function(element){
if(remove.includes(element.serial)){
console.log('Item to be removed:',element);
array.splice(array.indexOf(element),1);
}
});
console.log('New Length of Array:',array.length);
return array;
}
I am confused as to why this anomaly is occurring. Could someone kindly provide some insights on this matter?
Below is the console output for reference: