I have and array of objects which I would like to transform into single js object. The array contains target value and array of keys. Note: I want this to work in vanilla js without importing scripts.
The source array:
[
{ value: 'res-1', keys: [ 'first' ] },
{ value: 'res-2', keys: [ 'second', 'deeperOne' ] },
{ value: 'res-3', keys: [ 'second', 'deeperTwo' ] },
{ value: 'res-4', keys: [ 'second', 'deeperThree', 'moreDeeper' ] },
{ value: 'res-5', keys: [ 'third' ]}
]
Desirable result (object):
{
first: 'res-1',
second: {
deeperOne: 'res-2',
deeperTwo: 'res-3',
deeperThree: {
moreDeeper: 'res-4'
}
},
third: 'res-5'
}