数组去重

var a = [4,2,5,6,3,4,5]
 var hashTab = {}
 for(let i=0; i
var array=[4,5,4,7,2,4,6,7]
var result=array.sort().reduce((acc,cur)=>{
  if(acc[acc.length-1]!==cur){
    acc.push(cur)
  }
  return acc
},[])
console.log(result)
function unique(arr){
  var result=[]
arr.map(el=>{
    if(result.indexOf(el)===-1){
      result.push(el)
    }
  })
   return result
}
var a=[3,5,4,6,5,3,5,6,2]
console.log(unique(a))

你可能感兴趣的:(数组去重)