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,820
  • 5
  • 31
  • 56

5 Answers5

8

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
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
  • 2,006
  • 13
  • 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
  • 120,458
  • 37
  • 198
  • 307
1

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

loop arr to get each line.

anmarti
  • 5,045
  • 10
  • 55
  • 96
0

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

Riv
  • 1,849
  • 1
  • 16
  • 16