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

241
Vistas
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 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