Array.prototype.uniq = function () { // 1.使用集合快速去重 <!-- return Array.from(new Set(this)) --> // 2.使用数组的includes函数进行判断去重 let set = [] this.forEach(item => { if(!set.includes(item)) { set.push(item) } }) return set }
Array.prototype.uniq = function () { // 1.使用集合快速去重 <!-- return Array.from(new Set(this)) --> // 2.使用数组的includes函数进行判断去重 let set = [] this.forEach(item => { if(!set.includes(item)) { set.push(item) } }) return set }