-3

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?

Community
  • 1
  • 1
John Mitchell
  • 271
  • 4
  • 13

1 Answers1

0

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;
        }
    }
}
Julien Fouilhé
  • 2,583
  • 3
  • 30
  • 56