I have an array like this:
message_list = [
{
"Main_body": "test msg",
"emp_name": "test",
"emp_salary": "5000 USD"
}
]
Its length (e.g., message_list.length
) is 1.
Now I have another array like this:
added_user_data = [
{
"PostSharedLog": {
userids: "2,4,5"
},
"created": "2123123"
},
{
"PostSharedLog": {
userids: "3,1"
},
"created": "2123147"
}
]
Its length (added_user_data.length
) is 2.
I want to push the above array added_user_data
into message_list
.
I tried doing it inside a for
loop, now since the length of message_list is 1
, for the second iteration, the values do not get pushed since message_list[1]
does not exist and is undefined. But I still want to create message_list[1]
even if it does not exist.
if i do the below :
for(var k =0;<count(added_user_data.length);k++)
{
message_list[k].PostSharedLog = added_user_data[k].PostSharedLog ;
}
It only appends the first row from the array added_user_data
and gives an output like this when i print out message_list
:
[{
"Main_body": "test msg",
"emp_name": "test",
"emp_salary": "5000 USD",
"PostSharedLog": {
userids: "2,4,5"
} }]
The second iteration does not append anything at all .
I would like to see the below :
[{
"Main_body": "test msg",
"emp_name": "test",
"emp_salary": "5000 USD",
"PostSharedLog": {
userids: "2,4,5"
},
"PostSharedLog": {
userids: "3,1"
}
}]