I have an array of data (in reality a parsed CSV dump from MySQL with headers)
['adam', 'smith', 'honda', 'civic']
I have an object which defines how that array of data should look as an object.
{
first_name : 0,
last_name: 1,
car : {
make: 2,
model: 3
}
}
This object could have any depth of nested values. It is also dynamically generated.
My question is: how do I cast the values from the array to the object?
(I am trying to make a recursive function loop over the object and grab the array currently but keep running in to walls. If I get it to work I will post it, but I suspect there's an easier way to accomplish this.)
One of possible solutions !
Here is one way to do it. It works for the case you presented.
fiddle: http://jsfiddle.net/wy0doL5d/8/
You could try something like this:
This was a quick write. There may be some use cases I didn't account for but it does work for your data above. It can def be expanded on.
Fiddle: http://jsfiddle.net/qyga4p58/