遍历两个对象 并赋值.两个对象数组合并去重。

 Object.getOwnPropertyNames( _this.ruleForm).forEach(item =>{
            Object.getOwnPropertyNames(res).forEach(option =>{
              if(option == item){
                _this.ruleForm[item] = res[option]
              }
            })
          })

其中 Object.getOwnPropertyNames 为原生方法。

2.两个对象数组合并去重。

  
data.forEach((item) => {
          this.$set(item.data, "salePrice", "");
          this.projectSelectType.push(item.data)
        })
      let arrList = []
      for(let ops of this.projectSelectType){
        let flag = true;
        for(let items of arrList){
          if(ops.code == items.code){
            flag = false
          }
        }
        if(flag){
          arrList.push(ops)
        }
      }
this.projectSelectType = arrList;

 3.数组取并集(第二个是根据属性值取并集)

   this.projectSelectType = nodeArr.filter(val=>{
      return this.projectSelectType.indexOf(val) > -1
    })

this.projectSelectType.filter(x => nodeArr.find(y => y.code === x.code))

4.对象数组根据属性值去除并集

a.filter(x => !b.find(y => y._id === x._id));

5.对象数组去重

 arrayUnique2(arr, name) {
      let hash = {};
      return arr.reduce(function (item, next){
        hash[next[name]] ? '' : hash[next[name]] = true && item.push(next)
        return item;
      }, []);
    },

 

posted @ 2020-11-13 10:11  巫小婆  阅读(1500)  评论(0编辑  收藏  举报