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

287
Vistas
How to use map inside map using docx npm (javascript)

I am trying to use map inside another map when creating a table for a word file using npm package docx.

The file is created, but when I try to open it in word it says that the file format is not supported. Everything works fine if I don't use the second map function so I know this is the problem.

This is what I have:

export const createTable = (items) => { 
    let loopTables = items.map((item1) => 
                   
                new Table({
                    columns: 5,
                    width: 0, 
                    columnWidths: [2100, 1100, 1100, 1100, 1900], 
                    layout: TableLayoutType.FIXED,
                    rows: [
                        new TableRow({
                            children: [
                                new TableCell({
                                    children: [new Paragraph({
                                        children: [
                                            new TextRun({
                                                text: `Main item ${item1[0].Group1}`,
                                            }),
                                        ]
                                    }),],
                                    columnSpan: 5,
                                }),
                            ],
                        }),
                        item1.map((item2) =>
                        new TableRow({
                            children: [
                                new TableCell({
                                    children: [new Paragraph({
                                        children: [
                                            new TextRun({
                                                text: `Nested item ${item2.Group2}`,
                                            }),
                                        ]
                                    }),],
                                    columnSpan: 5,
                                }),
                            ],
                        }),
                        )
                    ]
                }),
            )
            return loopTables
}

loopTables is then inserted in another file like this:

{
                properties: {
                    type: SectionType.CONTINUOUS,
                },
                children: createTable(items) //Here we call the function that generates the table. It works fine without the nested map function.
            },

Any idea whats wrong and what I should do to fix it?

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

0

Solved it by using two classic for loops instead. The rows was saved in two variables and then pushed togheter to an empty array. Don't know why the map didn't work though

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