1
I’m using a variable object exp
:
var obj = {
nome: "Marcos",
snome: "Bonado",
idade: "314",
email: "[email protected]",
tellW: "0123456789"
};
I want to list the names and content of each object. Is there any way I can do this?
1
I’m using a variable object exp
:
var obj = {
nome: "Marcos",
snome: "Bonado",
idade: "314",
email: "[email protected]",
tellW: "0123456789"
};
I want to list the names and content of each object. Is there any way I can do this?
1
For no problem with browser incompatibility use the 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]);
}
}
0
Try it like this:
function (data) {
var keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
}
}
0
First you must create an array and store the objects. Then to list the objects in the array you can use the console.log(array). If you want to see the contents of each object in isolation you can make a loop for.
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]);
}
Browser other questions tagged javascript variables
You are not signed in. Login or sign up in order to post.
Can you explain better what you mean by "list names and content"?
– Sergio
Possible duplicate of Traverse an array without knowing its indices
– Marconi