JSFiddle - React, Tailwind, and code Playground
HTML
<pre id="text">
Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text. Lots of text. Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text.
Lots of text. Lots of text. Lots of text.
Lots of text.
Lots of text. Lots of text. Lots of text.
</pre>
JavaScript
function splitLines(aText) {
if (!aText) {
return [];
}
var reSplitLines = /.*(:?\r\n|\n|\r)?/mg;
var lines;
if (aText.match) {
lines = aText.match(reSplitLines);
} else {
var str = aText + "";
lines = str.match(reSplitLines);
}
lines.pop();
return lines;
}
var container = document.querySelector("pre");
console.log(splitLines(container.textContent));