因此對於一個數組咱們能夠直接採用java
const duplicateArr = [2,3,4,4,4,3]; const newArray = [...new Set(duplicateArr)]; console.log(newArray);
const duplicateArr = [2,3,4,4,4,3]; const newArray = duplicateArr.filter((value,index,arr)=>{ return arr.indexOf(value) === index; //或者 //return arr.findIndex(value) === index; }) console.log(newArray);
const duplicateArr = [2,3,4,4,4,3]; const newObject = {}; for(let i in duplicateArr) { if (!newObject[duplicateArr[i]]){ newObject[duplicateArr[i]] = 1;//只是記錄一下 } else { //這裏也能夠增長計數類的處理 } } console.log(Object.keys(newObject));