解构赋值
const obj = {
a:1,
b: 2,
c: 3,
d: 4,
};
const {a, b. c, d} = obj || {};
console.log(a)
const {a: a1} = obj || {};
console.log(a1)
合并两个对象
const obj1 = {
a: 1
}
const obj2 = {
b: 1
}
const obj3 = {...obj1,...obj2} // {a:1, b:1}
合并两个数组并去重
const a = [1,2,3]
const b = [1,3,4]
const c = [...new Set([...a,...b])] // [1,2,3,4]
if 条件判断
if (type==1 || type==2 || type==3) { ... }
const condition = [1,2,3,4];
if (condition.includes(type)) { ... }
从数组中找出符合的项
const a = [1,2,3,4,5]
const result = a.find(item => {
return item === 3
})
console.log(result) // 3
非空判断
if (value??'' !== '') { ... }
异步函数
const fn = async() => {
const res1 = await fn1();
const res2 = await fn2();
console.log(res1);
console.log(res2);
}
const fn = () => {
Promise.all([fn1(), fn2()]).then(res => {
console.log(res);
})
}