Home > Back-end >  JavaScript Map RangeError: Invalid array length
JavaScript Map RangeError: Invalid array length

Time:06-03

I am using the docx node library and attempting to autogenerate a table from an array. The challenge is that beyond returning data I need to return a structure, but when I run my map it fails with the following:

RangeError: Invalid array length

Here is my sample code I am testing with.

const rowChildren = [
    {firstName : "Susan", lastName: "Steward"},
    {firstName : "Daniel", lastName: "Longbottom"},
    {firstName : "Jacob", lastName: "Black"}
  ];

const table = new Table({
    rows: [rowChildren.map(function(element){ return new TableRow({
      children: [
        new TableCell({
        children: [new Paragraph(element.firstName)],
    }), //each entry is an array of TableCell that make up this row
],
    })},
),
],
  });

CodePudding user response:

Your map() already return an array TableRow[], just remove you [ ] before map() at rows key. This will resolve your RangeError: Invalid array length error.

  • Related