Q:

Write a JavaScript program to get an array of lines from the specified file

0

Write a JavaScript program to get an array of lines from the specified file.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const fs = require('fs');
const readFileLines = filename =>
  fs
    .readFileSync(filename)
    .toString('UTF8')
    .split('\n');
/*
contents of test.txt :
  line1
  line2
  line3
  ___________________________
*/
let arr = readFileLines('test.txt');

console.log(arr); // ['line1', 'line2', 'line3']

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now