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

178
Vistas
How do I add data from a file to an array in JavaScript?

I'm just trying to add some text from a text file to an array. I can get all of the text to print individually, but I cannot seem to add it to the array. The code that I have now is:

const fs = require('fs');
let wordList = []

fs.readFile('answers.txt', 'utf-8', (err, data) => {
    if (err){
        console.log(err);
    }
    else{
        wordList.push(data);
    }
});

console.log(wordList);

For the final console.log, I was expecting a long array, but instead I get an empty array. The issue is with the push function, but aside from that, I do not know another way to add to an array.

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