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

92
Vistas
ForEach inside Foreach Javascript

Hi how do I loop trough an array i already looped trough? So i foreach the subarray and still having the the old array

array =  [
{
"DocNum": 210446, 
"DocType": "Test",
"DocumentLines": [
{
"LineNum": 0,
"ItemCode": "427"
}, 
{
"LineNum": 0,
"ItemCode": "34"
}
]
},
{
"DocNum": 210446, 
"DocType": "Test",
 "DocumentLines": [
{
  "LineNum": 0,
  "ItemCode": "427"
  }, 
  {
    "LineNum": 0,
    "ItemCode": "34"
    }
  ]
  }
 ]

for (let element of array) {
 newArray.push({
    key1: element.DocNum,
    key2: element.DocType,
    key3: element.DocumentLines[???].ItemCode
})}

So the array will look like this in the end

{ "key1":210446, "key2":Test, "key3": [{ItemCode: 34},{"ItemCode": 427}] }

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

0

You can map the itemCodes

element.DocumentLines.map(v => v.ItemCode)

This will return the array of ItemCodes from your first array.

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