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

291
Views
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 answers
Answer question

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 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!