javascript program that reads text file and converts to javascript array code example
Example 1: javascript convert file to array
var fs = require('fs');
var text = fs.readFileSync("./mytext.txt", 'utf-8');
var textByLine = text.split('\n')
Example 2: javascript read file lines into array vanilla
const fileList = event.target.files;
let fileContent = "";
const fr = new FileReader();
fr.onload = () => {
fileContent = fr.result;
console.log('Commands', fileContent);
}
fr.readAsText(fileList[0]);