function array_diff(array1, array2){
var o ={};//转成hash可以减少运算量,数据量越大,优势越明显。
for(var i =0, len = array2.length; i < len; i++){
o[array2[i]]=true;
}
var result =[];
for(i =0, len = array1.length; i < len; i++){
var v = array1[i];
if(o[v])continue;
result.push(v);
}
return result;
}
var array1 =[3,4,5,96,7,8];
var array2 =[1,2,3,4,5,6];
alert(array_diff(array1, array2));//96,7,8
alert(array_diff(array2, array1));//1,2,6