javaScript цикл через значения объекта
var myObj = {foo: "bar", baz: "baz"};
Object.values(myObj).map((val) => {
console.log(val);
})
// "bar" "baz"
Thoughtful Tamarin
var myObj = {foo: "bar", baz: "baz"};
Object.values(myObj).map((val) => {
console.log(val);
})
// "bar" "baz"
var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
const obj = { a: 1, b: 2 };
Object.keys(obj).forEach(key => {
console.log("key: ", key);
console.log("Value: ", obj[key]);
} );
for (var property in object) {
if (object.hasOwnProperty(property)) {
// Do things here
}
}
const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
// 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