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

Spread the love

To read line by line of a text area HTML tag with JavaScript, we call split on the text area’s value property.

For instance, we write

const textArea = document.getElementById("my-text-area");
const arrayOfLines = textArea.value.split("\n");

to select the text area with getElementById.

And then we get the text area’s value with the value attribute.

We call split with '\n' to split the value by the line breaks into an array oif lines.

Leave a Reply

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