I'm traversing n-depth nested objects (and arrays). I use a "breadcrumb" trail to determine a particular object's location, and delve through the object as so:
let i: number;
let obj: any = update.history.present;
let depth = 2
for (i = 0; i < path.length-depth; i++){
// do something if we're at the correct level, else:
obj = obj[path[i]];
}
Specifically, I overwrite obj with a new obj each time I go deeper, which makes each trip through the object one-way.
Is there another way to approach this, so I can go into the object, get some information, then go up n levels in the object and continue traversal, in potentially a different path?
Maybe I could make obj an array that holds each object level, allowing me to keep each traversal level as a sort of snapshot?