Another solution:
var jsonArray = [
{ name: "Alice", text: "a" },
{ name: "Bob", text: "b" },
{ name: "Carol", text: "c" },
{ name: "Dave", text: "d" }
];
jsonArray.forEach(function(json){
for(var key in json){
var log = "Key: {0} - Value: {1}";
log = log.replace("{0}", key); // key
log = log.replace("{1}", json[key]); // value
console.log(log);
}
});
If you want to target newer browsers, you can use Objects.keys:
var jsonArray = [
{ name: "Alice", text: "a" },
{ name: "Bob", text: "b" },
{ name: "Carol", text: "c" },
{ name: "Dave", text: "d" }
];
jsonArray.forEach(function(json){
Object.keys(json).forEach(function(key){
var log = "Key: {0} - Value: {1}";
log = log.replace("{0}", key); // key
log = log.replace("{1}", json[key]); // value
console.log(log);
});
});