Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two arrays into one array in angularjs?

This is my code

$scope.studentDetails=[];

$scope.studentDetails=[0][id:101,name:one]
                      [1][id:102,name:two]
                      [2][id:103,name:three] 

$scope.studentMarks=[];

$scope.studentMarks=[0][id:101,marks:78]
                    [1][id:102,marks:89]

i have two arrays,first array contains 2 properties like id and name, second array contains two properties like id and marks,i want to concatinate these two arrays into one array.i want to get output like

$scope.studentDetails=[0][id:101,name:one,marks:78]
                      [1][id:102,name:two,marks:89]
                      [2][id:103,name:three,marks:null]
like image 586
durga siva kishore mopuru Avatar asked Mar 05 '26 16:03

durga siva kishore mopuru


1 Answers

Lodash zip() should do that provided your JavaScript is valid in the first place.

$scope.studentDetails = _.zip($scope.studentDetails, $scope.studentMarks);

like image 131
Maurice Avatar answered Mar 07 '26 06:03

Maurice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!