Search code examples
angularjsarraysangularjs-scope

Convert Object to Array angularjs with dynamic value


{"13":"I","14":"E","15":"V","16":"G"}

to:

['I', 'E', 'V', 'G']

where the 0 property of objects have the array of 1 and 2 objects? Is there a way to do that?

<div ng-repeat="data in data" >
<label>
<input ng-model="student[data.stn_id]"  ng-true-value="'{{data.stn_name}}'" ng-false-value="" /><span>{{data.stn_name}}</span>
                            </label>
                        </div>
                       {{student}}

Thanks


Solution

  • var x = {"13":"I","14":"E","15":"V","16":"G"};
    
    var result = [];
    angular.forEach(x, function (value, key){
        result.push(value);
    });
    
    console.log(result); // [I,E,V,G]