Read line by line of a text file using JavaScript

I have a file called "newfile.txt" which has two lines of text in it


Lights Turned on
Lights turned off

I have a javascript function which reads the text file and i can access the output through the variable called "status" (see below) and when i console log "status" I can see both the lines present in newfile.txt.

Javascript ( to read the text file)

var status;
function readTextFile1(file)
    var rawFile = new XMLHttpRequest();"GET", file, false);
    rawFile.onreadystatechange = function ()
        if(rawFile.readyState === 4)
            if(rawFile.status === 200 || rawFile.status == 0)
               status = rawFile.responseText;

 readTextFile1("newfile.txt"); //calling the function


Now the problem is, I need to use an if statement based on the text in each line

For example ( just my concept)

if ( status (line 1) = "Lights Turned Off" ){
do something

if ( status (line 2) = "Lights Turned On" ){
do something

Any help is appreciated. Thanks a lot for your time.

91 thoughts on “Read line by line of a text file using JavaScript”

  1. Hey there! Someone in my Facebook group shared this website with us so I came to give it a look.
    I’m definitely enjoying the information. I’m book-marking and will be tweeting this to
    my followers! Terrific blog and amazing design and style.

  2. It’s perfect time to make some plans for the longer term and it
    is time to be happy. I have read this submit and if I may just I
    wish to counsel you few fascinating issues or advice.
    Perhaps you can write next articles referring to this article.
    I wish to learn even more issues about it!

  3. What i don’t understood is in fact how you’re not actually much more smartly-favored than you may be right now.

    You’re so intelligent. You realize therefore considerably relating to this topic, made me
    in my view consider it from a lot of various angles. Its like women and men don’t seem to be interested until it is something to accomplish with Lady gaga!
    Your own stuffs excellent. At all times deal with
    it up!

  4. Hi there just wanted to give you a quick heads up and let
    you know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and
    both show the same outcome. scoliosis surgery scoliosis surgery

  5. Pingback: aralen 50 mg
  6. Pingback: tamoxifen drug
  7. Pingback: buy clomid pills
  8. Pingback: nolvadex buy
  9. I’m extremely impressed together with your writing talents
    as smartly as with the format in your blog. Is that this a paid theme or did you customize
    it your self? Either way stay up the nice quality writing,
    it’s rare to see a nice blog like this one these days..

  10. I was curious if you ever thought of changing the
    structure of your site? Its very well written; I love what youve
    got to say. But maybe you could a little more in the way of
    content so people could connect with it better. Youve got an awful lot
    of text for only having one or 2 pictures. Maybe you could space it
    out better?

  11. Hello there! This is my first comment here so I just wanted to
    give a quick shout out and tell you I really enjoy reading
    through your blog posts. Can you recommend any other blogs/websites/forums that deal with the same subjects?
    Thank you!

  12. hey there and thank you for your information – I’ve definitely picked
    up anything new from right here. I did however expertise some technical issues using this web site, as I experienced to reload the
    website a lot of times previous to I could get it to load correctly.
    I had been wondering if your web host is OK? Not that I am complaining,
    but slow loading instances times will sometimes
    affect your placement in google and could damage your quality score if ads and marketing with Adwords.
    Anyway I’m adding this RSS to my e-mail and can look out for a lot
    more of your respective exciting content. Make sure you update this again soon.