Reputation: 9293
I have two arrays first array connections Array
[
{
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'
}
]
count Array
[
{
type: 'facebook',
count: 4
},
{
type: 'twitter',
count: 1
}
]
Here am pushing the second array into first array
connections.push(count);
My requirement is how to add key values in to the joined array like the following way. I need to add accounts and count keys before each array. Please help me to find one solution. Thanks
{
"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
}
]
}
Upvotes: 0
Views: 65
Reputation: 92775
You can do it like
var result = {
accounts: accountsArray,
counts: countsArray
}
(or)
var result = {
}
result.accounts = accountsArray;
result.counts = countsArray.
You do not need array.push
.
Upvotes: 1
Reputation: 10090
you want to create a new object, not an array:
new_object = {
"accounts" : account_array,
"count": count_array
}
Upvotes: 1