“JavaScript Fromentries” Code-Antworten

JavaScript konvertieren Objekt.enteilt zurück in das Objekt

const arr = [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ];
const obj = Object.fromEntries(arr);
console.log(obj); // { 0: "a", 1: "b", 2: "c" }
Winged Ketchup

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..}
Rocket Noob

Ähnliche Antworten wie “JavaScript Fromentries”

Fragen ähnlich wie “JavaScript Fromentries”

Weitere verwandte Antworten zu “JavaScript Fromentries” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen