gpt4 book ai didi

javascript - 在Javascript中推送两个带有键值的数组

转载 作者:行者123 更新时间:2023-12-02 17:30:34 25 4
gpt4 key购买 nike

我有两个数组,第一个数组连接数组

[
{
account_id: '1000024965925119facebook',
account_name: 'JijoJohn',
account_image: '5133_a.jpg',
account_type: 'facebook'
},
{
account_id: '100002496592511facebook',
account_name: 'JijoJohn',
account_image: '55133_a.jpg',
account_type: 'facebook'
},
{
account_id: '138115932930527facebook',
account_name: 'JijoJohn',
account_image: '5555133_a.jpg',
account_type: 'facebook'
},
{
account_id: '101706396580621facebook',
account_name: 'JijoJohn',
account_image: '55133_a.jpg',
account_type: 'facebook'
},
{
account_id: 'feed1',
account_name: 'JijoJohn',
account_image: '5555133_a.jpg'
},
{
account_id: '57880525twitter',
account_name: 'MinuJose',
account_image: 'b4_normal.png',
account_type: 'twitter'
}
]

计数数组

[
{
type: 'facebook',
count: 4
},
{
type: 'twitter',
count: 1
}
]

这里将第二个数组插入第一个数组

connections.push(count);

我的要求是如何将键值添加到连接的数组中,如下所示。我需要在每个数组之前添加帐户和计数键。请帮我找到一种解决方案。谢谢

{ 
"accounts" :
[
{
account_id: '57880525twitter',
account_name: 'MinuJose',
account_image: 'b4_normal.png',
account_type: 'twitter'
},
{
account_id: '57880525twitter',
account_name: 'MinuJose',
account_image: 'b4_normal.png',
account_type: 'twitter'
}
],
"count" :
[

{
"type":"facebook",
"count": 4
} ,
{
"type":"twitter",
"count": 1
}
]
}

最佳答案

你可以这样做

 var result = {
accounts: accountsArray,
counts: countsArray
}

(or)

var result = {
}
result.accounts = accountsArray;
result.counts = countsArray.

您不需要array.push

关于javascript - 在Javascript中推送两个带有键值的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23101658/

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