I am trying to compare 2 arrays using jquery and remove duplicates from that.
This is my code.Is this logic correct?
var list1 = [6, 7, 3, 4, 1, 2];
var list2 = [2, 4, 6, 5, 1, 9, 8, 7, 8];
var newArray = [];
var index1, index2;
$.each(list1, function(i, value)) {
index1 = $.inArray(list1[i]);
index2 = $.inArray(newArray[i]);
if (index2 == -1) {
newArray.push(list2[i]);
}
}
Expected output:
[3,5,9,8]