Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda