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

143
Vistas
Finding the name of an object

Let's say I have some Javascript with the following:

Foo = {
    alpha: { Name: "Alpha", Description: "Ipso Lorem" },
    bravo: { Name: "Bravo", Description: "Nanu, Nanu" },
    delta: { Name: "Fly with me", Description: "Klaatu barata nikto" }
};

Table = [ Foo.alpha, Foo.bravo, Foo.delta];

x = Table[1];

Is there any way of looking at x and getting the identifier bravo? I'm fully aware that I can use x.Name or x.Description, but let's say that I need to know the name for something elsewhere. In one task I experimented with, I was forced to add a redundant id : "bravo" to each entry, but that was a pain.

My gut tells me it can't be done. But I'm hoping someone else can tell me otherwise.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Foo = {
    alpha: { Name: "Alpha", Description: "Ipso Lorem" },
    bravo: { Name: "Bravo", Description: "Nanu, Nanu" },
    delta: { Name: "Fly with me", Description: "Klaatu barata nikto" }
};

Table = [ ];
for(let val in Foo){
  let obj = Foo[val];
  obj = {...obj , id:val }
  Table.push(obj)
}
x = Table[1];
console.log(x)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Personally, I'd use a Proxy ...

const _Foo = {
    alpha: { Name: "Alpha", Description: "Ipso Lorem" },
    bravo: { Name: "Bravo", Description: "Nanu, Nanu" },
    delta: { Name: "Fly with me", Description: "Klaatu barata nikto" }
};
const Foo = new Proxy(_Foo, {
    get(target, id) {
        if (target.hasOwnProperty(id)) {
           return {...target[id], id};
        }
        return target[id];
    }
});
const Table = [ Foo.alpha, Foo.bravo, Foo.delta ];
console.log(Table[0])

about 4 years ago · Juan Pablo Isaza Denunciar
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