数组去重concat合并使用

1.使用函数调用参数,来对数组进行concat合并处理指向apply调用this执行函数

function combine(){
  let arr=[].concat.apply([],arguments); //这里是没有去重,是进行合并数组
 return Array.from(new Set(arr)); //set可以过滤掉重复的数字
}
var m =[1,2,3,2],n=[2,3,4];
console.log(combine(m,n))

//(4) [1, 2, 3, 4]

2.在Array.from中使用箭头函数
Array.from([1,2,3],x=>x+x);
//[2,4,6]

生成遍历数组
Array.from({length:5},(v,i)=>i);
//[0,1,2,3,4,5]


posted @ 2022-03-05 15:14  cc-front  阅读(554)  评论(0)    收藏  举报