showing results for - "js array from text file"
Andrea
11 Oct 2019
1const fs = require('fs')
2
3const makeArrayFromTextFile = (path) => {
4  const text = fs.readFileSync(path, 'utf-8')
5  const textByLine = text.split('\n')
6  return textByLine
7}
8
9const array = makeArrayFromTextFile('./array.txt') 
10
11console.log(array) // ['apple', 'orange', 'strawberry']
12  
13// array.txt
14apple
15orange
16strawberry
17