如果数组中个元素是字符串,这么做方便,如果不是,那就用@lyw_2008_happy的方法就行
var arr1 = ['a','b','c','d'];var arr2 = ['x','b','c','y'];
var long = arr1length<arr2lengtharr2:arr1;
var short = arr1length<arr2lengtharr1:arr2;
var str = ","+longtoString()+",";
var result=[];
for(var i in short){
if(strindexOf(","+short[i]+",")>=0){
resultpush(short[i]);
}
}
alert(resulttoString());
如果是完全一样的数组,可以简单的把数组转字符串后进行判断,否则只能通过循环判断
(function() {var arr1 = [1, 2, 3];
var arr2 = [1, 2, 3];
alert(arr1toString() == arr2toString()); //true
})();var str = "";
for(var i = 0; i < numlength; i++){
str += num[i]toString() + ",");
}
for(var j = 0; j < maxlength; j++){
str = strReplace(max[j]toString() + ",","");
}
//剩下来的就是max中没有的值了,你需要的就是按,分隔取出就行了var array1 = [ {"Num": "A " },{"Num": "B" }];
var array2 = [ {"Num": "A ","Name": "t1 " }, {"Num": "B","Name": "t2"}, {"Num": "C " ,"Name": "t3 "}];
var result = [];
for(var i = 0; i < array2length; i++){
var obj = array2[i];
var num = objNum;
var isExist = false;
for(var j = 0; j < array1length; j++){
var aj = array1[j];
var n = ajNum;
if(n == num){
isExist = true;
break;
}
}
if(!isExist){
resultpush(obj);
}
}
consolelog(result);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)