I have two array,
arr = [2,5,5,4,5,4,5,4,8,4,5]
delitem = [5,4];
I have to remove those items from arr
, which item is in delitem
.
Here is the my way,
var arr = [2,5,5,4,5,4,5,4,8,4,5];
var delitem = [5,4];
for(let i = 0; i < arr.length; i++){
for(let j=0; j < delitem.length; j++){
if(arr[i] === delitem[j]){
const index = arr.indexOf(delitem[j]);
arr.splice(index,1);
}
}
}
console.log(arr);
What I get is,
[ 2, 5, 5, 5, 8, 5 ]
What I’m expecting is,
[2,8]
Please give me some suggestion to fix it