var a = [5,6,5,4, ' 3 ', {},3, ' character ']
Method One: Create a new array, use IndexOf to determine whether it exists in the new array, not present the push to the new array, and finally return the new array
function Unique0 () { = []; for (Let i = 0;len = A.length,i < Len;i + +) {if(Arr.indexof (a[i]) = = = 1) { arr.push (A[i]) } } return arr } Console.log (Unique0 (a))
Method Two: Use Object object to save the array value, determine whether the array value has been saved in the object, not saved then push to the new array and record the Save in Object[arrayitem]=1 way
function Unique1 (a) { = []; = {}; for (Let i = 0;len = A.length,i < Len; i + +) {typeof A[i] + a[i ]if(!
hash[key]) { = 1
; Ret.push (A[i]) } }
return
ret } Console.log (Unique1 (a) )
Method Three: ES6 new data structure set, new method Array.from
function Unique2 (a) { new Set (a) return array.from (arr) } Console.log (Unique2 (a))
Three easy-to-use array-to-weight methods