js数组去重几种方法
2021-04-14 06:27
标签:filter final 四种 ons repeat result lte for i++ // 第二种 O(2n) // 第三种 //第四种includes() == -1 //第五种filter js数组去重几种方法 标签:filter final 四种 ons repeat result lte for i++ 原文地址:https://blog.51cto.com/14582569/2511674
function remove(arr){
return [...new Set(arr)]
}
console.log(remove([1,2,3,4,5,5,5,5]));
function removeColone(arr){
let final = [];
for(let i = 0 ;i
final.push(arr[i]);
}
}
console.log(final)
}
removeColone([1,2,2,3,3,4,4,5,5,5,5,7,8,9,9])
function rmoveProtype(arr){
let tem ={};
for(let i = 0;i${arr[i]}
] = ‘a‘
}
let result=Object.keys(tem).map(res=>{
return parseInt(res)
})
return result;
}
function removeRepeat(arr){
var tem = [];
for(let i = 0;i
tem.push(arr[i])
}
}
console.log(tem)
}
function removeRepeat(arr){
return arr.filter((currentValue,index,arr)=>{
return arr.indexOf(currentValue) ===index
})
}
console.log(removeRepeat([1,2,2,3,3,4,5,5,5,5]))