9.ES6-set去重

set去重

var demo = new Set([1,1,3,5,4,6]);
console.log([...demo]); // [1, 3, 5, 4, 6]

 合并两个数组,合并两个对象。

const a = [1,2,3];
const b = [1,5,6];
const c = a.concat(b);//[1,2,3,1,5,6]

const obj1 = {
  a:1,
}
const obj2 = {
  b:1,
}
const obj = Object.assign({}, obj1, obj2);//{a:1,b:1}

改进

const a = [1,2,3];
const b = [1,5,6];
const c = [...new Set([...a,...b])];//[1,2,3,5,6]

const obj1 = {
  a:1,
}
const obj2 = {
  b:1,
}
const obj = {...obj1,...obj2};//{a:1,b:1}

 

上一篇:day8-字符串和集合作业


下一篇:jenkins 安装