I have two lists that I want to combine as key value pairs:
keys = ['Jan 2016', 'Feb 2016', 'Mar 2016'];
values = ['janData', 'febData', 'marData'];
The desired outcome I want is:
dataMap = {
'Jan 2016': 'janData',
'Feb 2016': 'febData',
'Mar 2016': 'marData'
};
I looked at In Javascript a dictionary comprehension, or an Object `map` and saw there are ways to build an object using .reduce()
or assign()
given an existing array. However I couldn't figure out how to adapt those methods when I have two arrays.
Question: How can I construct my dataMap
object from two existing arrays?
It seems object comprehensions have gotten some updates in recent years. assign()
seems to be pretty new, but maybe it's not the best tool for my task. Also, I'm using native javascript only.