ES6数组去重
作者:互联网
利用ES6剩余参数加数组API forEach遍历每一个参数并加入到一个新数组中在遍历完成返回一个new Set处理后的新数组 ,这个新数组就是去重后的数组
let quchong = (...arr)=>{
let newArray = [];
arr.forEach((item, index)=>{
newArray = [ ...newArray, ...item ];
})
return [...new Set(newArray)]
}
let newArray = quchong([1, 2, 3], [3, 4, 5], [6, 7, 8, 9, 9, 9]) // 1,2,3,4,5,6,7,8,9
标签:ES6,arr,...,let,newArray,数组,quchong 来源: https://blog.csdn.net/qq_43402051/article/details/121470131