一、用对象更方便
const list = new Map().set('a', ['a1', 'a2']).set('b', ['b1', 'b2']).set('c', ['c1', 'c2']);
const selectList = (select) => list.get(select);
console.log('selectList', selectList('a')); // ['a1', 'a2']
二、解构删除一个对象属性
const person = {
name: 'job',
age: '12',
height: '178',
work: 'palying'
}
const { work, ...newPerson } = person;
console.log(newPerson);
// {
// name: 'job',
// age: '12',
// height: '178',
// }
三、使用Set去重数组
- 注意这里会有一些兼容性问题,具体看这里https://caniuse.com/
const arr = [1, 2, 2, 3, 3, 3, 4, 6];
const newArr = [...new Set(arr)] // [1, 2, 3, 4, 6]