javascript - How can I append an array of objects to an already existing array? -
this question has answer here:
i created following array:
$scope.testaccounts[0] = { id: 99, name: "select account" };
i tried
$scope.testaccounts.push(result.data);
where results.data looks this:
[{ id: 1, name: "x" },{ id: 2, name: "y" }]
however not seem work tries add array second element. need have contents of array result.data appended array $scope.testaccounts
please note examples have seen far seem not work if array array of objects. have. thanks
you're looking array.concat
> foo = [1,2,3] [1, 2, 3] > foo.concat([4,5,6]) [1, 2, 3, 4, 5, 6]
Comments
Post a Comment