How to read .txt file line by line

J

jobo

Hey all,

If I have a text file (example.txt) and I want to read that in with
javascript and parse through it line by line, how would I do that?

For example if I had
balthazar
epitome
blah
diggit

The first line would be "balthazar"
The second line would be "epitome"
etc.. etc..

Thanks!
 
S

scripts.contact

Hey all,

If I have a text file (example.txt) and I want to read that in with
javascript and parse through it line by line, how would I do that?

For example if I had
balthazar
epitome
blah
diggit

The first line would be "balthazar"
The second line would be "epitome"
etc.. etc..


you can use split method. for example, if the content of file is on
fileContent variable then you can simply use:

fileLines=fileContent.split("\n")

first line will be:
fileLines[0]

second:
fileLines[1]

third:
fileLines[2]

.....

and the number of lines:
fileLines.length
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top