Categories
JavaScript Answers

How to read line by line of a text area HTML tag with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *