Considering the following two arrays. How can I append array "lines" to array "array1". I have tried .push but it appends outside of the array. I have also tried .unshift which doesn't give me the wanted result.
array1 = [
{
"Activity #": "1111111",
"Customer": "Last, First",
"Tenure": "0 Year 2 Months",
"Account #": "0000000"
}];
lines = [
{
"Line #": "1",
"Action Required": "New",
"Status": "Closed",
"Product Line": "test line1",
"Product": "product1"
},
{
"Line #": "2",
"Action Required": "New",
"Status": "Closed",
"Product Line": "test line2",
"Product": "product2"
}];
I would like something like this.
my_array = [
{
"Activity #": "1111111",
"Customer": "Last, First",
"Tenure": "0 Year 2 Months",
"Account #": "0000000",
"lines": [{
"Line #": "1",
"fields": "keys"
},
{
"Line #": "2",
"fields": "keys"
}]
}]
With the mentioned used methods I get something like.
my_array = [
{
"Activity #": "1111111",
"Customer": "Last, First",
"Tenure": "0 Year 2 Months",
"Account #": "0000000"
}, [
{
"Line #": "1",
"fields": "keys"
}, {
"Line #": "2",
"fields": "keys"
}]
];
Hope someone can help and my question is clear.
-
@Allan: As far as I can tell, this has nothing to do with JSON.Felix Kling– Felix Kling2014年03月06日 00:18:21 +00:00Commented Mar 6, 2014 at 0:18
-
Yep I confirm, nothing to do with json, shorcut mistake while editing.Allan Stepps– Allan Stepps2014年03月06日 00:20:47 +00:00Commented Mar 6, 2014 at 0:20
1 Answer 1
It looks like you want to add lines as property to object inside the array, so you'd have to do:
array1[0].lines = lines;
You haven't explained what exactly should happen if you have more elements in array1, so I cannot say anything about that.