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

120
Vistas
Javascript i need to show data in table from dynamic object keys

Hello everyone I have a array of objects now those objects hold have multiple keys and those keys are dynamic so I have no idea how can I loop through data and show them in the table I am not sure how can I access those when I loop through. I was able to get the object keys into a separate array but don't how to utilize them. Here is the array of data and the array of keys can anyone guide or help me

This is the data array

var data = {
"data": [
        {
            "nationality": "Indonesia",
            "gender": "Male",
            "country": "Indonesia",
            "preferred_role": "Customer Service",
            "work_experience": "More than 1 year and less than 2 years",
            "preferred_work_environment": "Open to both",
            "count": 381
        },
              ]
    }

This is the keys array

["nationality", "gender","country","preferred_role","work_experience","count","preferred_work_environment"]
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This is a simple example of how iterates object's properties:

var data = {
    "data": [{
        "nationality": "Indonesia",
        "gender": "Male",
        "country": "Indonesia",
        "preferred_role": "Customer Service",
        "work_experience": "More than 1 year and less than 2 years",
        "preferred_work_environment": "Open to both",
        "count": 381
    }, ]
};

for (let i in data.data[0]) {
    console.log(i);
}

For more details, you can read:

  • for...in
  • Iteration protocols
about 4 years ago · Juan Pablo Isaza Denunciar

0

By using object.entries you can get key and values of a object.

for (const [key, value] of Object.entries(data.data[0])) {
      console.log(`${key}: ${value}`);
    }

By this method you will get array of keys so,you can use them

Object.keys(data.data[0])

By this method you will get values of a object

Object.values(data.data[0]) 
about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is a snippert that lets you list all key/value pairs of all objects contained in a data array:

const data = {"data": [{
            "nationality": "Indonesia",
            "gender": "Male",
            "country": "Indonesia",
            "preferred_role": "Customer Service",
            "work_experience": "More than 1 year and less than 2 years",
            "preferred_work_environment": "Open to both",
            "count": 381
           },{
            "nationality": "German",
            "gender": "Female",
            "country": "France",
            "passion": "coding",
            "preferred_role": "Support",
            "work_experience": "More than 20 years",
            "preferred_work_environment": "virtual",
            "count": 524
           } ] };
           
document.querySelector("table").innerHTML = data.data.map(ob=>
    "<tr><td><table>"
   +Object.entries(ob).map(el=>`<tr><td class="rgt">${el.join(":</td><td>")}</td></tr>`).join("")
   +"</table></td></tr>").join("");
   
.border > tbody > tr > td { border: solid 1px grey }
.rgt { text-align: right }
<table class="border"></table>

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