javascript - Data massaging in json response -


this question has answer here:

i have written following code in angular $http service call

  var country = "http://localhost:3000/json/country.json";         $http.get(timezoneurl).then(function (response) {             $ctrl.timezone = response.data;             console.log(response.data);         }); 

everything works fine , getting response below.

  [{     "region": "africa",     "country": "south africa"   },   {     "region": "europe",     "country": "spain"   }]; 

i have json response massaged , update key ui. want response in following format

 [{      "value": "africa",      "label": "south africa"    },    {      "value": "europe",      "label": "spain"  }]; 

you can use array.prototype.map();

var countries = [{"region": "africa","country": "south africa"},{"region": "europe","country": "spain"}],      formattedcountries = countries.map(function(c) {        return {          'value': c.region,          'label': c.country        };      });    console.log(formattedcountries);


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -