遍歷兩個對象 並賦值.兩個對象數組合並去重。


 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