Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Traversing an object in JS. Is there a way to go *up*?

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!