Kalashri Aundhkar Kalashri Aundhkar - 12 days ago 4
Javascript Question

Assign value from one array as a key to another array using lodash javascript

I have 2 arrays -

1-

Numbers = [3,4,5]


2-
selection= [ [1,2,3,4],[6,5,4,3],[2,9,4]]


Now in output I want 3 should be key i.e index of
[1,2,3,4]
and so on

Output should be below -

selection= = { '3':[1,2,3,4] ,'4':[6,5,4,3] ,'5':[2,9,4]}

Answer

just use _.zipObject https://lodash.com/docs/4.17.2#zipObject

_.zipObject(Numbers, selection)
Comments