Is there a way to convert an array of arrays into a JavaScript object? The condition being that the first element of each internal array becomes a key in the new object, with the following elements as its corresponding values?
If the first element occurs more than once within the internal arrays, can we ensure only one key is created for that element?
For instance:
var arr = [['a', 'b'], ['c', 'd'], ['a', 'e']]
The expected result would be:
var obj = {a: ["b", "e"], c: ["d"]}
In this example, even though a
appeared twice in arr
, only one key a
was created in the final object along with key c
.