Looking to create a map from JSON data returned by a RESTFUL WEB Service using AngularJS.
Here is an example of the JSON format:
myJSON = [{
id: 8,
color: "red",
value: "#f00"
},
{
id: 37,
color: "green",
value: "#0f0"
},
{
id: 45,
color: "blue",
value: "#00f"
}]
The goal is to build a map using id & value from the JSON provided. An initial idea might look like this:
var map = [myJSON.id : myJSON.value]
This would result in a map like:
map = {8: "red", 37: "green", 45: "blue"}
While a simple solution involves looping through the JSON array to construct the map, are there alternative methods to achieve this goal?