js combine object.entries code example

Example 1: javascript combine objects

const obj1 = {'a': 1, 'b': 2};
const obj2 = {'c': 3};
const obj3 = {'d': 4};

const objCombined = {...obj1, ...obj2, ...obj3};

Example 2: javascript fromEntries

// JS fromEntries => list of key-values transformation into an object
    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);
    });
// expected output = Object { name: "Skitty", species: "cat", age: 9 etc..}