【发布时间】:2019-12-10 08:29:30
【问题描述】:
我有这样一个数组
const arr = [
{id: 1, title: 'qwer', children: []},
{id: 2, titile: 'sparta', children:
[
{id: 21, title: 'sdf', children: []},
{id: 11, title: 'change me', children: []}
]
}
]
我需要编辑一个对象{id: 11, title: 'change me', children: []};
我就是这样做的
const newData = dataCopy.map(el => {
if(el.Id === this.titleId){
return {
...el,
Title: val
}
}
return el;
});
问题是我不知道如何在子数组中找到目标对象。如何找到它并返回新数组?
【问题讨论】:
-
你试过双循环还是双
find? -
在地图内使用过滤器
标签: javascript arrays