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