loop in object javascript
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);let obj = {
key1: "value1",
key2: "value2",
key3: "value3"
}
Object.keys(obj).forEach(key => {
console.log(key, obj[key]);
});
// key1 value1
// key2 value2
// key3 value3
// using for in - same output as above
for (let key in obj) {
let value = obj[key];
console.log(key, value);
}var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[property]);
}const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}var person = {"name":"Rasel", age:26};
for (var property in person) {
console.log(person[property]);
}