获取一个数组中相同的属性的对象数组

initDependLink(arr) {
let links = {};
for (let item of arr) {
if (!links[item.target]) {
links[item.target] = [];
}
links[item.target].push(item.source);
}
let relas = [];
for (let key in links) {
let item = {
relaType1: "e2b",
relaType2: "AND",
fromIds: links[key],
toIds: [key]
};
relas.push(item)
}
console.log(relas);
},
posted @ 2019-04-20 17:15  不服憋着  阅读(497)  评论(0编辑  收藏  举报