// 1. 合并数组/对象
// 数组(考虑去重)
let a = [1, 2, 3];
let b = [4, 5, 6];
let c = [... new Set([...a, ...b])];
// 对象
let obj1 = { a: 1 };
let obj2 = { b: 2 };
let obj = { ...obj1, ...obj2 };
// console.log(c, obj);
// 2. 模板字符串,在${}中可以放入任意的JavaScript表达式,可以进行运算,以及引用对象属性。
let name = '小明';
let score = 59;
let result = `${name}${score < 60 ? '考试不及格' : '考试合格'}`;
// console.log(result);
// 3. includes 函数(数组和字符串)
let a3 = [1, 2, 3, 4];
let type = 1;
// console.log(a3.includes(type)); // true
let str = "aabbcc";
let s = "aa";
// console.log(str.includes(s)); //true
// 4. find 函数,find方法中找到符合条件的项,就不会继续遍历数组
const a4 = [1, 2, 3, 4, 5];
let type4 = 1;
const result4 = a4.find(item => { return item === type });
// console.log(result4); // 1
type = 9;
// console.log(result4); // undefined
// 5. 数组扁平化 flat(num) ; num 扁平化维度; num == Infinity-> 其中使用Infinity作为flat的参数,使得无需知道被扁平化的数组的维度。
// flat方法不支持IE浏览器。
const deps = {
'采购部':[1,2,[3,6,9]],
'人事部':[5,8,12],
'行政部':[5,14,79],
'运输部':[3,64,105],
}
let member = Object.values(deps).flat(Infinity);
// console.log(member);
// 6. 关于输入框非空的判断
// if(value !== null && value !== undefined && value !== ''){
// //...
// }
// 修改为
// if(value??'' !== ''){
// ...
// }
// 7. 异步函数 async await
const fn = async () =>{
const res1 = await fn1();
const res2 = await fn2();
console.log(res1);// 1
console.log(res2);// 2
}
// 但是要做并发请求时,还是要用到Promise.all()。
// 如果并发请求时,只要其中一个异步函数处理完成,就返回结果,要用到Promise.race()。