ES6 常用函数

forEach 循环数组对象,不会跳出循环

arr.forEach(function (item, index, arr) {
    // item,单个对象
    // index 索引
    // arr完整的集合对象
});

获取对象数组中某一个属性的value集合

arr为对象数组,name是对象的属性名称,返回value数组集合

      var keys = Array.from(arr,({name}) => name);

reduce,待完善,仅供参考

   
      var arr = self.$children.reduce((components, child) => {
        if (child.$options.name === componentName) {
          if(dataSourceKey.indexOf( child.widget.options.remoteDataSource) >=0){
            components.push(child);
          }
          return components;
        }else{
          const foundChilds = this.findChildrensComponent(child, componentName,dataSourceKey);
          return components.concat(foundChilds);
        }
      }, []);
posted @ 2022-03-21 20:49  亘古不变  阅读(6)  评论(0)    收藏  举报  来源