-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
「幾乎相同」的定義是什麼? –