gpt4 book ai didi

javascript - 合并/组合两个对象

转载 作者:行者123 更新时间:2023-11-30 08:43:25 25 4
gpt4 key购买 nike

我有两个来自两个不同来源的不同数组,我需要合并它们以形成一个新数组。这是两个数组:

[
{
"Litsname": "Fruit Basket",
"Listid": "1",
}
]

还有,

[
{
"id": "4",
"name": "Apples",
"categoryID": "2",
"categoryName": "Fruits"
},
{
"id": "5",
"name": "Orange",
"categoryID": "2",
"categoryName": "Fruits"
}
]

我想合并/组合它们以形成以下数组:

[
{
"Litsname": "Fruit Basket",
"Listid": "1",
"item": [
{
"id": "4",
"name": "Apples",
"categoryID": "2",
"categoryName": "Fruits"
},
{
"id": "5",
"name": "Orange",
"categoryID": "2",
"categoryName": "Fruits"
}
]
}
]

尝试使用 jQuery extend 但它看起来不适合这个。关于如何使用 jQuery/纯 JavaScript 实现此目的的任何帮助?

最佳答案

如果第一个叫a,第二个叫b,那么你只需要说a[0].item = b

关于javascript - 合并/组合两个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24110919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com