我有两个对象数组,我需要在 listOfRegistries.Id === listOfTargets.regId 的新数组中引入名称
this.listOfRegistries = [
{ id: '123', name: 'name1' },
{ id: '245', name: 'name2' },
];
this.listOfTargets = [
{ regId: '123',key: 'value1' },
{ regId: '245', key: 'value2' },
];
我需要实现这一点:
this. listOfTargetsNew = [
{ regId: '123',key: 'value1', name: 'name1' },
{ regId: '245', key: 'value2', name: 'name2' },
];
这就是我正在尝试但没有结果
this.listOfTargetsNew = this.listOfTargets.map((el, index)=> {
if( this.listOfRegistries[index].id === el.regId) {
el['name'] = this.listOfRegistries[index].name;
return el;
}
});
非常感谢您的回复。