I have a collection of paired items, and I am looking to convert it into a dictionary.
const collection = [['apple', 3], ['banana', 5]]
const transformed = {'apple': 3, 'banana': 5}
If I were using Python, I could simply do
>>> dict([['apple', 3], ['banana', 5]])
{'apple': 3, 'banana': 5}
What's the most straightforward way (1-line solution) to accomplish this in JavaScript?
Though I initially thought it would take 2 lines of code.
const collection = [['apple', 3], ['banana', 5]]
const transformed = {}
collection.forEach(([key, value]) => transformed[key] = value)