I'm using a object exp
variable:
var obj = {
nome: "Marcos",
snome: "Bonado",
idade: "314",
email: "[email protected]",
tellW: "0123456789"
};
I want to list the names and contents of each object. Is there any way for me to do this?
I'm using a object exp
variable:
var obj = {
nome: "Marcos",
snome: "Bonado",
idade: "314",
email: "[email protected]",
tellW: "0123456789"
};
I want to list the names and contents of each object. Is there any way for me to do this?
To have no problem with incompatibility between browsers use for
var obj = {
nome: "Marcos",
snome: "Bonado",
idade: "314",
email: "[email protected]",
tellW: "0123456789"
};
for (var k in obj){
if (obj.hasOwnProperty(k)) {
console.log("Chave: " + k + ", Valor: " + obj[k]);
}
}
First you must create an array and store the objects. Then to list in the console the objects of the array you can use console.log (array). If you want to see the contents of each object in isolation you can make a for loop.
For example:
var objeto = {"nome":"Bruno"};
var objeto2 = {"nome": "teste"};
var array = [objeto, objeto2];
console.log(array);
for(var i=0; i < array.length; i++){
console.log(array[i]);
}
Try this:
function (data) {
var keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
}
}