Turning to @ AR7 answer , in case there are objects in each of them, you can cache the object returned by Object.keys() and cycle through each property in the array loop.
Using the method below, you can handle any number of properties inside an object.
I understand that this may not be more useful in this particular situation than the above answer, but I hope it will be useful to future viewers.
Jsfiddle
var a = [ { "bg_2":"0.50", "bg_7":"0.10", "bg_12":"0.20"}, { "bg_2":"0.50", "bg_7":"0.10"}, { "bg_2":"0.50"} ]; a.forEach(function(o){ console.log(o); var k = Object.keys(o); for(var i in k) console.log(k[i], ':', o[k[i]]); });
source share