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

334
Views
Using loop to add to docx.js Document

I am using docx.js to create a Word document from text that is entered into a textarea. I have created an array (arrayOfLines) which splits the textarea contents at each new line.

I now want to add this array to the Document using a loop function, and the code I am using does not seem to work. Hoping someone might be able to help, as I could not find many answers here so far. Apologies if I haven't been clear, this is my first question. Thank you.

    saveEssay () {
   var arrayOfLines = document.getElementById('textArea').value.split('\n');
    

    const buildParagraph = async()=>{
      let paragraphArray = []
      for (var i = 0; i < arrayOfLines.length; i++){
        paragraphArray.push(new Paragraph({text: arrayOfLines[i].text }))
      }
    return paragraphArray;
  };


    let doc = new Document({
    sections: [
      {
        headers: {
                default: new Header({
                    children: [new Paragraph("Page heading")],
                }),
            },
        children: [
          new Paragraph({ text: "My Essay", heading: HeadingLevel.HEADING_2 }),
          buildParagraph() // paragraphs are not coming through 
        ]
      }
    ]
  });
}
about 4 years ago · Juan Pablo Isaza
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!