const uniqueArr = (arr) => arr.reduce((acc, current) => {
if(!acc.find(item => item === current)) {
return acc.concat(current)
}
return acc
}, [])
var a = [1,1,2,3,4]
uniqueArr(a) // [1, 2, 3, 4]
const uniqueArr = (arr) => arr.reduce((acc, current) => {
if(!acc.find(item => item === current)) {
return acc.concat(current)
}
return acc
}, [])
var a = [1,1,2,3,4]
uniqueArr(a) // [1, 2, 3, 4]
本文标题:去重
本文链接:https://www.haomeiwen.com/subject/wtpcvdtx.html
网友评论