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

Comments

Popular posts from this blog

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

ng-show doesn’t work correct with value boolean

ng-include of inline SVG does not display gradient except in Chrome