1 var arr1=[ 2 [1,2,3,4,5], 3 [1,2,3,4,5], 4 [12,3,4], 5 [6,7,8], 6 [32,2] 7 ]; 8 var arr2=[ 9 [1,2,3,4,5], 10 [6,7,8], 11 [6,7,8], 12 [15,16] 13 ]; 14 console.log(fillterArr(arr1,arr2));// ["12,3,4"] ["15,16"] ["32,2"]
方法:
1 function fillterArr(arr1,arr2){ 2 3 var arr11=stringTo(arr1); 4 var arr22=stringTo(arr2); 5 function stringTo(ar){ 6 var arr=[]; 7 for(var i=0;i<ar.length;i++){ 8 arr.push(ar[i].toString()); 9 } 10 return arr; 11 } 12 function unique(arr){ 13 // 遍历arr,把元素分别放入tmp数组(不存在才放) 14 var tmp = new Array(); 15 for(var i in arr){ 16 //该元素在tmp内部不存在才允许追加 17 if(tmp.indexOf(arr[i])==-1){ 18 tmp.push(arr[i]); 19 } 20 } 21 return tmp; 22 } 23 function GetRepeatFwxmmc(ary1){ 24 var ary = ary1.sort();//数组排序 25 var cffwxmsAry = new Array(); 26 //所有重复元素添加进新数组内 27 for(var i=0;i<ary.length;i++){ 28 if (ary[i]==ary[i+1]){ 29 cffwxmsAry.push(ary[i]); 30 } 31 } 32 var result = [], isRepeated; 33 //对重复元素数组进行元素去重 34 for (var k = 0; k < cffwxmsAry.length; k++) { 35 isRepeated = false; 36 for (var j = 0;j < result.length; j++) { 37 if (cffwxmsAry[k] == result[j]) { 38 isRepeated = true; break; 39 } 40 } 41 if (!isRepeated) { 42 result.push(cffwxmsAry[k]); 43 } 44 } 45 return result; 46 } 47 var arr1111=unique(arr11); 48 var arr2222=unique(arr22); 49 50 var arr01=arr1111.concat(arr2222); 51 //重复的数组值 52 var arr02=GetRepeatFwxmmc(arr01); 53 function getData(a,b){ 54 55 var c=[]; 56 var arr00=[]; 57 for(var i in a){ 58 c[a[i]]=a[i]; 59 } 60 for(var i in b){ 61 if(c[b[i]]){ 62 delete c[b[i]]; 63 }else{ 64 c[b[i]]=b[i]; 65 } 66 } 67 for(var i in c){ 68 arr00.push(c[i].split()) 69 } 70 return arr00; 71 } 72 73 return getData(arr01,arr02); 74 }