Friday, October 6, 2017

Assign key to array using angularjs

Hi i am having a array like below

$scope.Selectedgroups =[183,184,24]

i need to convert to the below format

 [{groupId:183},{groupId:184},{groupId:24}];

trying to convert by using for loop

var groups=[]
        if($scope.Selectedgroups.length > 0){
            for(i=0; i< $scope.Selectedgroups.length; i++){
                groups.push({"groupId":$scope.Selectedgroups});
            }
        }

getting array format as below:

[{"groupId":[183,184,24]},{"groupId":[183,184,24]},{"groupId":[183,184,24]}]

any solution please

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/06/assign-key-to-array-using-angularjs/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment