I need help converting an array into an object where the keys are based on whether the index of the array is odd or even.
For example:
Input:
["name", "Tom", "age", 20]
Output: {"name": "Tom", "age": 20}
I know this can be achieved using basic JavaScript functions like forEach
, map
, and filter
, but I'm looking for a simpler solution.
I've explored the underscore.js documentation, but couldn't find a suitable method. Is there an easier way to accomplish this task?