I know how to convert this:
const keys = [1, 2, 3];
To this:
[{key: 1, val: "q"}, {key: 2, val: "w"}, {key: 3, val: "e"}]
With a single mapping statement:
keys.map((x, i) => ({key: x, val: "qwe".charAt(i)}));
But I would actually like to get this:
{1: "q", 2: "w", 3: "e"}
Is there a neat way to do this in a single statement similar to the one above?
[1, 2, 3].reduce((p, c, i) => (p[c] = "qwe"[i], p), {});, alternative:Object.fromEntries([1, 2, 3].map((e, i) => [e, "qwe"[i]]));Object.assign, so i think we got all the common ways. Wonder if there are some unfeasible but fun ways.