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

163
Vistas
Intento acceder a los elementos de la matriz pero no estoy definido

No puedo acceder a los elementos de la matriz. No he puesto el código completo porque es demasiado largo pero explico lo que he hecho.

Tengo una matriz de resultados del siguiente tipo:

results [i] = myArr.Items [i]

o así hecho:

 {3: {...}, 4: {...}, 9: {...}} 3: {type: 'Image', id_a: '123456', value: 'moto_guzzi_v100_mandello.jpg', number: 3, id: 3} 4: {type: 'Text', id_a: '123456', value: 'The star of the Piaggio group stand is without doubt ... Discover all her secrets with our video', number: 2, id: 2} 9: {type: 'Text', id_a: '123456', value: 'The V100 Mandello celebrates the 100th anniversary of the house and… ovative. Let's find out together with our video. ', Number: 4, id: 4}

y estoy tratando de recuperar los elementos como se muestra en el siguiente código:

 Object.entries(results).forEach(function (item) { let child = document.createElement("tr"); child.innerHTML = ` <td>${item.number}</td> <td>${item.type}</td> <td>${item.value}</td> table.appendChild(child); })
 <table id="my-table" width="90%"> <tr> <th>Number</th> <th>Type</th> <th>Value</th> </tr> </table>

Solo obtengo el valor undefined para cada valor.

¿Puede alguien amablemente explicarme la forma correcta de acceder a estos valores?

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

0

No use Object.entries . La forma correcta de iterar sobre su matriz es:

 for (const i in results) { const item = results[i]; let child = document.createElement("tr"); child.innerHTML = ` <td>${item.number}</td> <td>${item.type}</td> <td>${item.value}</td> table.appendChild(child); }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Object.entries() hace que su lista de objetos sea iterable, pero si console.log cada item , verá que es una matriz con 2 entradas: el índice (0) y los datos (1)

 let results = { 3: { type: 'Image', id_a: '123456', value: 'moto_guzzi_v100_mandello.jpg', number: 3, id: 3 }, 5: { type: 'Text', id_a: '123456', value: 'The star of the Piaggio group stand is without doubt ... Discover all her secrets with our video', number: 2, id: 2 }, 8: { type: 'Text', id_a: '123456', value: 'The V100 Mandello celebrates the 100th anniversary of the house and… ovative. Let\'s find out together with our video. ', Number: 4, id: 4 } }; Object.entries(results).forEach(item => { item = item[1]; let child = document.createElement("tr"); child.innerHTML = ` <td>${item.number}</td> <td>${item.type}</td> <td>${item.value}</td>` document.querySelector('#my-table').appendChild(child); })
 <table id="my-table" width="90%" border='1'> <tr> <th>Number</th> <th>Type</th> <th>Value</th> </tr> </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