6

How can I read the contents of a text area line by line or split the text in different lines to obtain input as lines of text.

mickeymoon
  • 4,580
  • 5
  • 30
  • 52

5 Answers5

8

You're looking for the Javascript split() method.

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
7

Try this one....

you can split by "\n" and then get lilne by line value using for loop

var lines = $('textarea').val().split('\n');
for(var i = 0;i < lines.length;i++){
    //code here using lines[i] which will give you each line
}
Ganesh Rengarajan
  • 1,998
  • 11
  • 26
2

You can achieve it by using split() method.

 var splittedLines= inputString.split('\n');

And where splittedLines is an array.Loop through splittedLines to get the each line.

Suresh Atta
  • 118,038
  • 37
  • 189
  • 297
1

var arr = yourtext.split("\n");

loop arr to get each line.

anmarti
  • 4,935
  • 10
  • 50
  • 94
0

you can convert the value of the textarea to an array by splitting on the newline \n character

Riv
  • 1,839
  • 1
  • 16
  • 15