var arr1 = [ "574417bc79df540065d92df7", "574424e5df0eea0063adefc6", "57442329a3413100625f194f", "5744242bc4c971005d5ff04e", "574a841d1532bc006068c6c9", "574a97fe2b51e90056e423c0"];var arr2 = [ "574417bc79df540065d92df7", "57442329a3413100625f194f", "5744242bc4c971005d5ff04e", "574424e5df0eea0063adefc6", "574a841d1532bc006068c6c9"];如何快速地对比出这两个数组中不是同时存在的元素。目测答案是:"574a97fe2b51e90056e423c0"
1 回答
aluckdog
TA贡献1847条经验 获得超7个赞
比较初级的哈哈,
var lessArr,maxArr;if(arr1.length>arr2.length) { lessArr = arr2; maxArr = arr1; }else{ lessArr = arr1; maxArr = arr2; }var lessStr = lessArr.join('|');var diffArr = [];for(var i=0;i<maxArr.length;i++) { if(lessStr.indexOf(maxArr[i]) == -1) { diffArr.push(maxArr[i]); } }console.log(diffArr.join(','));
添加回答
举报
0/150
提交
取消