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

243
Visualizações
Is it possible in JS to know where a reference is in its hierarchy?

I have a case where I want to mark my 'posts' (like articles) with the country they belong to, while allowing to go a scope higher: example france < europe < world

This is how I structured my hierarchy: world.js

export default {
    world: {
        europe: {
            albania: 'albania',
            austria: 'austria',
            belgium: 'belgium',
            bulgaria: 'bulgaria',
            croatia: 'croatia',
            czech: 'czech',
            //...
            france: 'france'
    }
}

It is not necessary to have this structure. But what I want to achieve is that each 'post' I have would contain a location propoerty with a value like ['world', 'europe', 'france']. My pain is how to extract from the value 'france' its hierarchy ['world', 'europe', 'france'] without having to scan all the tree: I need kind of a reference to the property france to know to which 'context' it belongs to and navigate the tree in a child to parent way to obtain france (parent: europe (parent: world)) (not searching from the root where france might be in the structure)

Of course I can declare a verbose tree explicitly specifying the parent each time, but my question is about an elegant way of doing this

almost 4 years ago · Santiago Trujillo
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