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

247
Views
cómo mostrar el valor si el valor es una clave

Tengo este objeto pero el valor tiene el elemento clave y me pregunto cómo obtener el valor

Por ejemplo:

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

El código:

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

El HTML:

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

La cuestión:

Quiero mostrar el valor "456" en el segundo "td" pero el código no lo hace.

Qué cambio debo hacer para que el resultado se vea como el siguiente:

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

0

Supongo que todas las claves en el objeto agg son dinámicas. Por lo tanto, puedes probar esto :

 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

Lo más probable es que necesite usar 10.0 como clave. Algo como esto.

 agg[3]["10.0"].value

Pero 10.0 es una clave extraña, aunque válida.

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!