I had two array:
const keys = [a, b, c]
const values = [[], [], []]
I want to convert it to a 2d array:
const entries = [[a, []], [b, []], [c, []]]
How can I do it?
P.S. Actually I want to apply Object.fromEntries
to initialise an object in the end.
const x = {a: [], b: [], c: []}
3
Answers
You can use an Array.map for example
or forEach
or a reduce
const data = keys.map((key, index) => [key, values[index]]);
you can use this data like this : Object.fromEntries(data)
You may consider
Array.reduce
, to makeObject.fromEntries
obsolete: