// 通过ES6的new Set进行数组去重: // 1. 数字、字符串数组去重 let arr1 = [1, 2, 3, 1, 2, 3, '1', '1']; let newArr1 = [...new Set(arr1)]; console.log(newArr1); // [1, 2, 3, '1'] // 2. 对象数组去重 let arr2 = [ {a: '1', b: 'q'}, {a: '1', b: 'q'}, {a: '2', b: 'e'}, {a: '2', b: 'e'} ] let newArr2 = [...new Set(arr2.map(e => JSON.stringify(e)))].map(e => JSON.parse(e)) console.log(newArr2); // [{a: '1', b: 'q'}, {a: '2', b: 'e'}]