Sometimes, we want to read line by line of a text area HTML tag with JavaScript.
In this article, we’ll look at how to read line by line of a text area HTML tag with JavaScript.
How to read line by line of a text area HTML tag with JavaScript?
To read line by line of a text area HTML tag with JavaScript, we can use the string split
method.
For instance, we write
const textArea = document.getElementById("my-text-area");
const arrayOfLines = textArea.value.split("\n");
to select the text area with getElementById
.
Then we get the value of the text area with value
.
And then we call split
with '\n'
to split the text area value into an array of strings by the new line character.
Conclusion
To read line by line of a text area HTML tag with JavaScript, we can use the string split
method.