Reputation: 2402
I'm doing the push method between two Arrays to create a bigger Array. The two simple arrays I want to fix are:
[{"id":"11"},{"color":"blue","value":"14"}]
[{"id":"11"},{"color":"green","value":"25"}]
The code to push the two arrays is:
var totjunt = $('body').data('cesta_list').push(array_of_bought_colors_new);
With $('body').data('cesta_list');
I save the first array and then i try to push the second array.
Using console.log(JSON.stringify(totjunt));
I print the value throught the console but the problem is that the console prints only a number 2.
Upvotes: 0
Views: 133
Reputation: 227270
.push
doesn't return a new array. It returns the array's new length. The array is updated in-place.
Upvotes: 3
Reputation: 39649
You're logging the result of the push()
call, not the resulting array. Try this:
$('body').data('cesta_list').push(array_of_bought_colors_new);
var totjunt = $('body').data('cesta_list');
More specifically, push()
returns the length of the new array, not the array itself.
Upvotes: 4