/**
* chagearronetwoone
* 把两个数组相同对象key值的元素用第二个数组替换调第一个数组,前提第一个数组的元素的key值完全包含第二个数组的,且第一个数组元素与第二个不同的全部都改为--
* var onearr = [{ key1: "--" },{ key2: "a" },{ key3: "b" },{ key4: "7" },{ key5: "88" }];
* var twoarr = [{ key2: "aqqqqq" }, { key5: "88qqqq" }];
* flag="--"
* flag 为 不用第二个数组地替换的值的符号
* 替换后为onearr = [{ key1: "--" },{ key2: "aqqqqq" },{ key3: "--" },{ key4: "--" },{ key5: "88qqqq" }];
*/
chagearronetwoone (arr, arr2, flag) {
let aa = [];
let bb = [];
arr.map((item, index) => {
bb.push(index);
});
arr2.map(item2 => {
arr.map((item1, index) => {
if (Object.keys(item1)[0] === Object.keys(item2)[0]) {
aa.push(index);
}
});
});
aa.map((item, index) => {
this.$set(arr, item, arr2[index]);
});
let cc = this.getArrDifference(aa, bb);
cc.map(ite => {
this.$set(arr, ite, flag);
});
return arr;
},
网友评论