//二维数组去重 var arr = [ [1,2,3], [2,3,4], [4,5,6] ]; var newArr = []; for (var i=0; i < arr.length; i++) { for (var j=0; j < arr[i].length; j++) { var v = arr[i][j]; // 判断是否存在数组中,不存在在往下走 if(!newArr.includes(v)) { newArr.push(v); } } } console.log(newArr); //[1, 2, 3, 4, 5, 6] //二维数组只保留出现一次的值 var arr = [ [1,2,3], [2,3,4], [4,5,6] ]; var newArr1 = []; // 去重后的 var newArr2 = []; // 重复的 var newArr3 = []; // 只出现一次的 for (var i=0; i < arr.length; i++) { for (var j=0; j < arr[i].length; j++) { var v = arr[i][j]; // 判断是否存在数组中,不存在在往下走 if(!newArr1.includes(v)) { newArr1.push(v); } else { newArr2.push(v); } } } for (var i=0; i < newArr1.length; i++) { var v = newArr1[i]; if(!newArr2.includes(v)) { newArr3.push(v); } } console.log(newArr1); //[1, 2, 3, 4, 5, 6] console.log(newArr2); //[2, 3, 4] console.log(newArr3); //[1, 5, 6] //二维数组移除相同的数组 const arrays = [ [1, 2, 5, 6], [1, 2], [2, 3], [1, 2], [3, 4], [1, 2] ] const filterArray = array => { const newArray = []; array.forEach((currentValue) => { let isPush = true; newArray.forEach((currentValueIn) => { if (currentValueIn) { if (currentValue[0] === currentValueIn[0] && currentValue[1] === currentValueIn[1]) { isPush = false; } } else { newArray.push(currentValue) } }) if (isPush) { newArray.push(currentValue) } }) return newArray; } console.log(filterArray(arrays)); 结果: [ [1,2,5,6], [2,3], [3,4] ] let arr = [1,13,24,11,11,14,1,2] let arr1 = [] for (let i = 0; i < arr.length; i++) { if (arr1.indexOf(arr[i]) === -1) { arr1.push(arr[i]) } } console.log(arr) //[1,2,11,14,13,24]