kyserslick kyserslick - 9 days ago 6
AngularJS Question

Convert a JSON to map using underscore in angular

I'm new to underscore and I want to convert a json data on my controller that look like this :

{ENGLISH: "STOCK", FRENCH: "STOCK", UK: "акції"}


to this

[{key:"ENGLISH", value:"STOCK"}, {key:"FRENSH", value:"STOCK"}...]

Answer
var stocks = {ENGLISH: "STOCK", FRENCH: "STOCK", UK: "акції"};

_.map(stocks,function(value, key){ 
    return {
       key:key,
       value:value
    };
});