Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda