Js数组去重

方法一:使用reduce,includes
1.定义数组

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

【Js数组去重】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']

    推荐阅读