I wonder what's wrong with this
$(function() {
var arr1=new Array('A','B','C','D','E','F','G');
var arr2=new Array('F','D','B');
var arr3=arr1;
for(x=0; x<arr3.length; x++) {
if(jQuery.inArray(arr3[x],arr2) == -1) {arr3.splice(x, 1);}
}
alert(arr1.join(','));
alert(arr3.join(','));
});
I thought arr1 should still be Array('A','B','C','D','E','F','G'), but after this operation, arr1 becomes arr3. It doesn't make sense to me since the entire operation doesn't touch arr1 at all.
Found the answer after posting this. See duplicating arrays javascript splicing