zoukankan      html  css  js  c++  java
  • 关于一些es6整理

     // 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()。
  • 相关阅读:
    移动终端app测试点总结
    Android测试环境搭建(win7)
    Jenkins知识地图
    Jenkins快速上手
    接口测试总结
    性能测试总结(三)--工具选型篇
    性能测试总结(二)---测试流程篇
    性能测试总结(一)---基础理论篇
    网友评论诺基亚和Android
    手撕伪鸡汤,人事部门经理给你的八个职场忠告
  • 原文地址:https://www.cnblogs.com/linliu/p/15398183.html
Copyright © 2011-2022 走看看