www.webdeveloper.com
Results 1 to 2 of 2

Thread: Read the lines of a text file and store each line in an array using javascript.

  1. #1
    Join Date
    Mar 2013
    Posts
    6

    resolved Read the lines of a text file and store each line in an array using javascript.

    Hi friends,

    I want to read a text file which contains some names. the 1st line of the file is a number denoting the number of names in the file. sample file is like this

    Filename: sample.txt

    4
    abc
    def
    ghi
    jkl

    i want to read this file using javascript and store each line in a array. I dont want to browse for this file (sample.txt). the array should be loaded with the contents when the page is loaded. can any1 suggest some idea as soon as possible.

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Presumably you don't have a server-side language available.

    Probably the most practical way is an AJAX request, which you can research. Then where rq is your request object:

    Code:
    var myArray = rq.responseText.split( /\r?\n/ );
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles