0
I’m getting my ass kicked to make a very simple stop: assemble an object in Javascript by an array (exploded string).
I need to mount an object dynamically (recursive) like this:
{
caneta: { cor: { hexadecimal: null } }
}
just with that array: ['cor', 'caneta', 'hexadecimal']
I need to do this recursively, because my array can have 1 property, or 800.
Context
I have a function that reads all forms on my page and assembles, according to the name of each input, an object, and, according to the form id, stores everything within a parent object (date).
Example:
that:
<form id="batata">
<input name="tomate">
<input name="banana" value="123">
</form>
generates an object like this:
batata: {
tomate: null,
banana: '123',
};
I don’t understand why you want something recursive. And the order/hierarchy of the properties in the object is different even from the array order, as in your example?
– bfavaretto
She needs to call herself to get the same treatment in all cases, doesn’t she? And yes, it will be forward.
– Daniel Bonifácio
So the object is pen/color/Hex and the array is color/pen/Hex? Is that right? Is there a reason why it’s not in the same order? Criteria?
– bfavaretto