resultList = {time:'2019-11',records:[{name:'香蕉'},{name:'苹果'}]},{time:'2019-10',records:[{name:'香蕉'},{name:'苹果'}]}
data = [{time:'2019-11',records:[{name:'香蕉'},{name:'苹果'}]}]
resultList.forEach((item,index)=>{
let obj = data.find( it=>it.month == item.month )
if( obj ){obj.records.push(...item.records)}
else{
data.push(item)
}
})
本文介绍了一种使用JavaScript处理数组的高效方法,通过遍历数组并根据条件进行元素的合并或新增,实现数据的快速更新。这种方法适用于需要频繁更新数据结构的应用场景。
1527

被折叠的 条评论
为什么被折叠?



