const object = { a: 1, b: 2, c: 3 };
// method 1
Object.entries(object).forEach(([key, value]) => {
console.log(key, value)
});
//method 2
for (const key in object) {
console.log(key, object[key])
}
// same output
// a 1
// b 2
// c 3
var obj = {
first: "John",
last: "Doe"
};
//
// Visit non-inherited enumerable keys
//
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (var key in p) {
if (p.hasOwnProperty(key)) {
console.log(key + " -> " + p[key]);
}
}
// an easy way is to
const obj = {1: 'a', 2: 'b', 3: 'c',};
for (const i in obj)
console.log(obj[i]);
//it is a simple way to loop on values of an object
let obj = { first: "John", last: "Doe" };
for (const key in obj){
console.log(key)
consol.log(obj[key])
}
var loop = [];
for(var x = 0; x < 10; x++){
loop.push({value1: "value_a_" + x , value2: "value_b_" + x});
}
JSON.stringify({array: loop});