Anonymous
Как объединить два массива объектов на основе того же ключа в JavaScript? [закрыто]
Сообщение
Anonymous » 11 авг 2025, 15:40
У меня есть data.json , который содержит два актива массива и описания . Оба они имеют классическую и exantemid . Мне нужно объединить оба базы Classid и exantemid , которые имеют одинаковое значение .
Код: Выделить всё
[
{
"assets": [
{
"appid": 570,
"contextid": "2",
"assetid": "30229921998",
"classid": "1",
"instanceid": "2",
"amount": "1"
},
{
"appid": 570,
"contextid": "2",
"assetid": "22173415650",
"classid": "23",
"instanceid": "24",
"amount": "1"
},
{
"appid": 570,
"contextid": "2",
"assetid": "32225979206",
"classid": "34",
"instanceid": "53",
"amount": "1"
}
],
"descriptions": [
{
"classid": "1",
"instanceid": "2",
"currency": 0,
"background_color": ""
}
]
}
]
< /code>
Ожидаемый результат: < /p>
[
{
"appid": 570,
"contextid": "2",
"assetid": "30229921998",
"classid": "1",
"instanceid": "2",
"amount": "1",
"currency": 0,
"background_color": ""
},
{
"appid": 570,
"contextid": "2",
"assetid": "22173415650",
"classid": "23",
"instanceid": "24",
"amount": "1"
},
{
"appid": 570,
"contextid": "2",
"assetid": "32225979206",
"classid": "34",
"instanceid": "53",
"amount": "1"
}
]
Мне нужно объединить эти два, когда assets.classid === descriptions.classid && arsets.instanceid === descriptions.instanceid
>
Подробнее здесь:
https://stackoverflow.com/questions/797 ... javascript
1754916052
Anonymous
У меня есть data.json , который содержит два актива массива и описания . Оба они имеют классическую и exantemid . Мне нужно объединить оба базы Classid и exantemid , которые имеют одинаковое значение . [code][ { "assets": [ { "appid": 570, "contextid": "2", "assetid": "30229921998", "classid": "1", "instanceid": "2", "amount": "1" }, { "appid": 570, "contextid": "2", "assetid": "22173415650", "classid": "23", "instanceid": "24", "amount": "1" }, { "appid": 570, "contextid": "2", "assetid": "32225979206", "classid": "34", "instanceid": "53", "amount": "1" } ], "descriptions": [ { "classid": "1", "instanceid": "2", "currency": 0, "background_color": "" } ] } ] < /code> Ожидаемый результат: < /p> [ { "appid": 570, "contextid": "2", "assetid": "30229921998", "classid": "1", "instanceid": "2", "amount": "1", "currency": 0, "background_color": "" }, { "appid": 570, "contextid": "2", "assetid": "22173415650", "classid": "23", "instanceid": "24", "amount": "1" }, { "appid": 570, "contextid": "2", "assetid": "32225979206", "classid": "34", "instanceid": "53", "amount": "1" } ] [/code] Мне нужно объединить эти два, когда assets.classid === descriptions.classid && arsets.instanceid === descriptions.instanceid > Подробнее здесь: [url]https://stackoverflow.com/questions/79732024/how-to-merge-two-array-of-objects-based-on-same-key-in-javascript[/url]