数组去重,数据合并,数组合并去重等ES6语法
2019-04-10 本文已影响0人
诚实可靠小郎俊
数组去重
let arr1 = [1,2,3,4,2,3]
console.log([...new Set(arr1)])
数组合并
let arr1 = [1,2,3,4]
let arr2 = [5,6,7,8]
console.log([...arr1,...arr2])
数组合并去重
let arr1 = [1,2,3,4,2,3]
let arr2 = [5,6,7,8,5,6]
console.log([...new Set([...arr1, ...arr2])])
淘宝首页到底用了多少种标签(面试题)
new Set([...document.querySelectorAll('*')].map(v=>v.nodeName)).size
对象合并
let obj1 = {
name: 'hello',
age: 18
}
console.log({...obj1, name2: 'world', age2: '19'})
数组合并替换
let obj1 = {
name: 'hello',
age: 18
}
let obj2 = {
name: 'world',
age: 19
}
console.log({...obj1, ...obj2,name2: 'job', age2: '20'})