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.
Asked
Active
Viewed 1.4k times
5 Answers
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
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