JavaScript Map RangeError: Invalid array length
JavaScript Map RangeError: Invalid array length
我正在使用 docx node library 并尝试从数组自动生成 table。挑战在于,除了 returning 数据之外,我还需要 return 一个结构,但是当我 运行 我的地图时,它会失败并显示以下内容:
RangeError: Invalid array length
这是我正在测试的示例代码。
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
],
})},
),
],
});
您的 map() 已经 return 一个数组 TableRow[]
,只需在 rows
键的 map() 之前删除您 [ ]。这将解决您的 RangeError: Invalid array length 错误。
我正在使用 docx node library 并尝试从数组自动生成 table。挑战在于,除了 returning 数据之外,我还需要 return 一个结构,但是当我 运行 我的地图时,它会失败并显示以下内容:
RangeError: Invalid array length
这是我正在测试的示例代码。
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
],
})},
),
],
});
您的 map() 已经 return 一个数组 TableRow[]
,只需在 rows
键的 map() 之前删除您 [ ]。这将解决您的 RangeError: Invalid array length 错误。