数组去重
-
indexOf 方法
// indexOf function i(a) { var b = [] for (var i = 0; i < a.length; i++) { if (b.indexOf(a[i]) === -1) { b.push(a[i]) } } return b } var a = [1, 1, 1, 2, 3] console.log(i(a))
-
Set 方法
// ES6 Set function newArr(arr) { return Array.from(new Set(arr)) } var arr = [1,2,3,4,2,5,3,7,4,6] console.log(newArr(arr)) // [ 1, 2, 3, 4, 5, 7, 6 ]