get each item in an object javaascript code example
Example 1: for each element in object
var obj = {
first: "John",
last: "Doe"
};
//
// Visit non-inherited enumerable keys
//
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Example 2: js object for each
const obj = {
a: 1,
b: 2,
c: 3
};
for (let key in obj) {
console.log(key + " = " + obj[key]);
}
// Ausgabe:
// "a = 1"
// "b = 2"
// "c = 3"