Last active
December 27, 2015 16:09
-
-
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}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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