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

244
Views
how to display value if the value is a key

I have this object but the value has the key element and wondering how to grab the value

For example:

2:
    values: 123
3:
    values:
        10.0: 456

The code:

 <td>{  agg[2].values}</td>
 <td>{  agg[3].values}</td>

The HTML:

<td>123</td>
<td></td>

The issue:

I want to display the value "456" in the second "td" but the code is not doing it.

What change I need to do to make the result looks like the below:

<td>123</td>
<td>456</td>
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

I am assuming all the keys in the agg object are dynamic. Hence, you can try this :

const agg = {
  2: {
    values: 123
  },
  3: {
    values: {
      10: 456
    }
  }
};

const arr = [];

Object.keys(agg).forEach(key => {
  if (typeof agg[key].values === 'object') {
    Object.keys(agg[key].values).forEach(innerObjKey => {
        arr.push(agg[key].values[innerObjKey])
    })
  } else {
    arr.push(agg[key].values)
  }
});

console.log(arr);

about 4 years ago · Santiago Gelvez Report

0

You most likely need to use 10.0 as the key. Something like this.

 agg[3]["10.0"].value

But 10.0 is a weird key, although a valid one.

about 4 years ago · Santiago Gelvez 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!