I want to create a program where if the value of ‘Bab’: null, then babParagraph will not appear. However, when I create the following conditional statement, I encounter an error message saying ‘Cannot convert undefined or null to object’.
ps: im using docx
here my code snippet:
let babParagraph = null; // Initialize babParagraph with null
// check if item.bab isn't null
if (item.bab !== null) {
// if item.bab isn't null, create babParagraph
babParagraph = new Paragraph({
children: [
new docx.TextRun({
text: 'Bab ' + item.bab,
}),
new docx.TextRun({
text: 'nKetentuan Umum',
break: 1,
}),
],
alignment: AlignmentType.CENTER,
});
}
and then error appear:
var _name = Object.keys(value)[0];
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18745:32
at Array.forEach (<anonymous>)
at resolve (d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18743:1618743:16)
at d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18749:28
at Array.forEach (<anonymous>)
at resolve (d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18743:1618743:16)
at d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18749:28
at Array.forEach (<anonymous>)
at resolve (d:magangjson_ke_wordnode_modulesdocxbuildindex.cjs:18743:1618743:16)
Node.js v20.11.1