69
rated 0 times
[
76]
[
7]
/ answers: 1 / hits: 35552
/ 12 Years ago, thu, august 30, 2012, 12:00:00
Given two arrays, one with keys, one with values:
keys = ['foo', 'bar', 'qux']
values = ['1', '2', '3']
How would you convert it to an object, by only using underscore.js methods?
{
foo: '1',
bar: '2',
qux: '3'
}
I'm not looking for a plain javascript answer (like this).
I'm asking this as a personal exercise. I thought underscore had a method that was doing exactly this, only to find out it doesn't, and that got me wondering if it could be done.
I have an answer, but it involves quite a few operations. How would you do it?
More From » underscore.js