Array.prototype.unique = function(){
let temp = {}
let arr = []
let len = this.length // 谁调用的this就指向谁 arr
for (var i = 0; i < len; i++) {
if(!temp[this[i]]){
temp[this[i]] = ‘anything’
arr.push(this[i])
}
}
return arr
}
let numberArr = [1,23,4,5,1,3,5,3]
numberArr.unique() // [23,4]
数组去重
最新推荐文章于 2024-05-22 21:39:25 发布