JS Loop melalui objek
const obj = { a: 1, b: 2 };
Object.keys(obj).forEach(key => {
console.log("key: ", key);
console.log("Value: ", obj[key]);
} );
GreekLover
const obj = { a: 1, b: 2 };
Object.keys(obj).forEach(key => {
console.log("key: ", key);
console.log("Value: ", obj[key]);
} );
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
const array = ['hello', 'world', 'of', 'Corona'];
for (const item of array) {
console.log(item);
}
var colors=["red","blue","green"];
for(let col of colors){
console.log(col);
}
// red
// blue
// green
var subjects = {
'math': 85,
'physics': 75,
}
for (var i in subjects) {
console.log(i + ' : ' + subjects[i]);
}
// math : 85
// physics : 75
const person = {fname:"John", lname:"Doe", age:25};
let text = "";
for (let x in person) {
text += person[x];
}