乐趣区

关于javascript:Js数组去重

办法一:应用 reduce,includes
1. 定义数组

let numArr = ['1','9','9','7','0','4','1','2','2','4','0']

2. 封装一个去重办法 remove()

function remove(arr) {return arr.reduce((newarr,cur) => {if(newarr.includes(cur) === false) newarr.push(cur)
    return newarr
  },[])
} 

3. 执行去重办法
remove(numArr)

4. 输入后果
['1','9','7','0','4','2']

退出移动版