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


 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;
      }, []);
    },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM