mardi 17 février 2015

deep nested obj property from indexes


I need to create "path" for nested arrays object only from indexes

I have:



var indexes = [2, 4, 5, 1]; //it can be any length


...and from that I need to create this (to get/set value):



myArray[2].children[4].children[5].children[1].property = someValue;


Right now I'm using recursive function loops to fetch desired object, but since function calls can be very frequent per second and target deeply nested, I would like to create path to object once, and use it on every call instead of looping.

I can't use eval !!!

how can I concatenate those array indexed elements into proper JS code path?

ps. pls correct me if "path" is not the right term.





Aucun commentaire:

Enregistrer un commentaire