1

I am using the following code to get contents from a csv file

$.get(file , function(data) {

  var lines = data.split('\n');

  $.each(lines, function (lineNo, line) {
    var items = line.split(',');
    // MORE STUFF
  });
});

The above code gives me all the lines that are available in my csv file. Here is an example of the data returned

one,0,0,
two,0,0
three,0,0

What i would like is to retrieve only a specific line from the file. for example "two,0,0"

How do i acheive this ?

Thanks

1 Answer 1

1

Once you split a string, the result is a numeric array with each portion of the string. So all of your lines are now numbered like any other numeric array. If you wanted the second line, you would just use the key to ask for it:

var lines = data.split("\n");
var secondLine = lines[1];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.