I have an array like this
var arrayFilterKeyValues=[{id:1,name:"one"},{id:2,name:"2"}..]
I have another array like this
var valuesArr=["1","2","3","4"...]
Now I am trying to delete elements from arrayFilterKeyValues
if the id's are in valuesArr
. This is the code I am using
for (var i = 0; i < arrayFilterKeyValues.length; ++i) {
var found = false;
for (var k = 0; k < valuesArr.length; k++) {
if (arrayFilterKeyValues[i].id == valuesArr[k]) {
found = true;
break;
}
}
if (found) {
delete arrayFilterKeyValues[i];
}
}
This is deleting the elements but when I check the array it has commas(,
) in the array and when I check the length it is still showing the length of the array prior to deletion of elements. What am I doing wrong here? Need a solution compatible for IE8+