-2
我有一个数组,其中包含几乎相同的对象。我想将这些对象合并为一个,同时保持它们之间不同的数据。如何将两个几乎相同的JavaScript对象合并为一个使用Lodash的对象?
这里是我的数据:
[
{ id: 1,
title: 'The title',
description: 'The description',
categories: [
{id: 1, name: 'Cat 1'}
]
},
{ id: 1,
title: 'The title',
description: 'The description',
categories: [
{id: 2, name: 'Cat 2'}
]
}
]
我想最后的结果是:
[
{ id: 1,
title: 'The title',
description: 'The description',
categories: [
{id: 1, name: 'Cat 1'},
{id: 2, name: 'Cat 2'}
]
}
]
任何帮助,将不胜感激!
试用['_.mergeWith()']给出的示例(https://开头lodash的.com /文档#mergeWith)。 –
Stackoverflow不是您粘贴数据和所需结果并获得解决方案的地方。我们在这里帮助,而不是为你思考。 – Aristarhys
“几乎相同”的定义是什么? –