Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda