js object from entries code example
Example 1: javascript object entries
const object1 = {
a: 'somestring',
b: 42
}
Object.entries(object1)
.forEach(([key, value]) => console.log(`${key}: ${value}`))
Example 2: javascript convert Object.entries back to object
const arr = [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ];
const obj = Object.fromEntries(arr);
console.log(obj);
Example 3: js object entries
var obj = { foo: 'bar', baz: 42 };
console.log(Object.entries(obj));
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.entries(obj));
Object.entries(obj).forEach(([key, value]) => {
console.log(key + ' ' + value);
});
Example 4: js entries
const object1 = { a: 'somestring', b: 42 };
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 5: javascript fromEntries
const keys = ["name", "species", "age", "gender", "color"];
const values = ["Skitty", "cat", 9, "female", "tabby"];
const run = document.getElementById("run");
run.addEventListener("click", function () {
let createObj = [];
keys.forEach((item, index) => {
createObj.push([item, values[index]]);
});
const object = Object.fromEntries(createObj);
console.log(object);
});