1. 程式人生 > >數據操作處理(數組拼接,去重)

數據操作處理(數組拼接,去重)

nbsp ret ldr code span children UNC 數據 push

1.數組處理添加與拼接

          this.treeListData.push(res.payload.results.OADepartment);
                  var treeList = this.treeListData[0].children;
                  var treeL = [];
                  treeList.forEach(el =>{
                      if(el.children){
                        treeL.push(el.children);//添加到數組
                      }
                  });
                  var treeLi = [];
                  var len = treeL.length;
                  for(var i=0;i
<len;i++){ treeLi.push.apply(treeLi,treeL[i]);//拼接數組 } this.listSecondDepart = treeLi;

2.數組對象排重reduce()

var hash = {};
            var arr = this.listCheckDepart;
            arr = arr.reduce(function(item, next) {
                hash[next.id] ? ‘‘ : hash[next.id] = true && item.push(next);
                return item
            }, [])
            this.listCheckDepart = arr;

數據操作處理(數組拼接,去重)