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"}...]
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"}...]
var stocks = {ENGLISH: "STOCK", FRENCH: "STOCK", UK: "акції"};
_.map(stocks,function(value, key){
return {
key:key,
value:value
};
});
You can approach this using only angular also
var input = {ENGLISH: "STOCK", FRENCH: "STOCK", UK: "акції"};
var output = [];
angular.forEach(input, function(v, k) {
this.push({key: k, value: v});
}, output);