Loop JavaScript através do objeto
var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Bald Eagle
var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
for (var property in object) {
if (object.hasOwnProperty(property)) {
// Do things here
}
}
var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[property]);
}
const point = {
x: 10,
y: 20,
};
for (const [axis, value] of Object.entries(point)) {
console.log(`${axis} => ${value}`);
}
/** prints:
* x => 10
* y => 20
*/
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (var key in p) {
if (p.hasOwnProperty(key)) {
console.log(key + " -> " + p[key]);
}
}
for (variable in object) {
statement
}