samedi 21 mars 2015

JavaScript Unshift EACH array element


I have two arrays that contain objects. arr1 and arr2. If I unshift arr1 to contain the elements of arr2, the elements are not appended individually into arr1, instead the whole array (arr2) is appended at the beginning, for example:



arr1 = [{ele:1}, {ele:2}]
arr2 = [{ele:3}, {ele:4}]


I get: arr1 = [[{ele:3}, {ele:4}], {ele:1}, {ele:2}]


Notice the whole array inside instead of its objects.


I want: arr1 = [{ele:3}, {ele:4}, {ele:1}, {ele:2}]


My arrays are ko.observableArray(), maybe that makes a difference?





Aucun commentaire:

Enregistrer un commentaire