GitHub 6219★

Create an object from the pairs of key and value

JavaScript version

const toObj = (arr) => Object.fromEntries(arr);

// Or
const toObj = (arr) => arr.reduce((a, c) => ((a[c[0]] = c[1]), a), {});

Examples

toObj([
['a', 1],
['b', 2],
['c', 3],
]); // { a: 1, b: 2, c: 3 }
Follow me on and to get more useful contents.