Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!