Answers for "js array from text file"

0

js array from text file

const fs = require('fs')

const makeArrayFromTextFile = (path) => {
  const text = fs.readFileSync(path, 'utf-8')
  const textByLine = text.split('\n')
  return textByLine
}

const array = makeArrayFromTextFile('./array.txt') 

console.log(array) // ['apple', 'orange', 'strawberry']
  
// array.txt
apple
orange
strawberry
Posted by: Guest on August-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language