String for an array within a loop - javascript/nodejs

Asked

Viewed 234 times

0

i want to pass the strings of a txt file to an array and as soon as each line was passed to the array the program would run it normally, then he would repeat and pick up the second string of the txt file. Everything is being done in javascript/nodejs only it’s been 2 days since I stopped at it and can’t get out of the corner.

loop code with the file and array:

function email_parser(){
var fs = require('fs');
var email_count = "";
var array = [];

var array = fs.readFileSync('email.txt').toString().split("rn");
for(var i = 0; i < array.length; i++) {
    email_count = array[i];
}}

and I’m calling it the variable this way

email = email_parser();

Thank you!.

1 answer

0

You’re separating the lines the wrong way, you have to use "\".

Forehead like this:

.split(/\n/).map(line => line.trim());
  • Didn’t work :/

  • @jorleidedasilva strip the .toString(), the . readFileSync already gives you a string.

  • @jorleidedasilva if you still can’t give me an example of the text, or put the file online to create an example for you to see.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.