Reputation: 2196
I have 2 arrays,
$scope.first = [
{ fName:'Alex', lName='Doe' },
{ fName:'John', lName='S' }
]
var second= [
{ fName:'Tom', lName='M', email:'[email protected]' },
{ fName:'Jerry', lName='L', email:'[email protected]' }
]
I need to push second array into first array and want to result like:
$scope.first = [
{ fName:'Alex', lName='Doe' },
{ fName:'John', lName='S' },
{ fName:'Tom', lName='M', email:'[email protected]' },
{ fName:'Jerry', lName='L', email:'[email protected]' }
]
Upvotes: 0
Views: 4257
Reputation:
$scope.first = [
{ fName:'Alex', lName='Doe' },
{ fName:'John', lName='S' }
]
var second= [
{ fName:'Tom', lName='M', email:'[email protected]' },
{ fName:'Jerry', lName='L', email:'[email protected]' }
]
$scope.first = $scope.first.concat(second)
Upvotes: 0
Reputation: 18905
If you want to push elements from one array into an existing array you can do
[].push.apply($scope.first, second);
If you want to create a new array that contains elements of both arrays, use concat:
$scope.first = $scope.first.concat(second);
Upvotes: 2