Skip to content

Instantly share code, notes, and snippets.

@dhilipsiva
Last active December 27, 2015 16:09
Show Gist options
  • Save dhilipsiva/7353239 to your computer and use it in GitHub Desktop.
Save dhilipsiva/7353239 to your computer and use it in GitHub Desktop.
i have this json { cb="Adiesel", litros=47}, Object , Object { cb="Gasolina 95", litros=1327}, Object { cb="Gasolina 98", litros=130}, i need to transform this in { "Adiesel"=47, "Gasóleo"=1008, "Gasolina 95"=1327, "Gasolina 98"=130}
var key, obj, res={}, _i, _len;
collection = [
{cb:"Adiesel", litros:47},
{cb:"Gasóleo", litros:1008}
// etc
];
trans = function(collection){
for (_i = 0, _len = collection.length; _i < _len; _i++) {
obj = collection[_i];
res[obj.cb] = obj.litros;
}
return res;
}
console.log(trans(collection));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment