Possible Duplicate:
JavaScript array difference
Using jquery or javascript how do I compare 2 arrays so that if one array has elements within the other array these elements are eliminated from the other array?
Possible Duplicate:
JavaScript array difference
Using jquery or javascript how do I compare 2 arrays so that if one array has elements within the other array these elements are eliminated from the other array?
You must cross the two array and compare each element of the first with each element of the second, then, use the Array.splice
method to remove an element.
for (var i in array1) {
for (var j in array2) {
if (array2[j] == array1[i]) {
array2.splice(j, 1);
break;
}
}
}