How to push some data from Json into new array in AngularJS? -


let's have json ..

{     "name": "mark",     "gender": "male",     "account1": {         "accountno": 1201,         "balance": 300     },     "account2": {         "accountno": 1354,         "balance": 5000     } }     

what expect ..

$scope.myarray = [     {         "accountno": 1201,         "balance": 300     },     {         "accountno": 1354,         "balance": 5000     } ]; 

in angularjs, how can pick part of json data , push array iteratively( mean, when have account1, account2 account3 or more, can still add them array).

you assign array over, in scenario not option because array psuedo.

ideally able answer (related question) does: how return , array inside json object in angular.js simply

$scope.myarray = json.accounts; 

however, noted, not have accounts array need make one.

var accounts = []; for(var key in json){  if( !json.hasownproperty(key) // skip prototype extensions   || !json[key].hasownproperty("accountno") //skip non account objects  ) continue;   accounts.push(json[key]); } 

and may use array

$scope.myarray = accounts; 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -