For the purpose of animating headings word by word, I am attempting to divide a string by spaces. However, my CMS outputs line breaks as \n
within the string.
const text = "Aenean non odio erat.\n Suspendisse vestibulum vulputate nulla et mollis."
const splitText = (text) => {
const words = text.split(' ')
return words
}
console.log(splitText(text))
When using this code, the result obtained is:
[
"Aenean",
"non",
"odio",
"erat.\n",
...
]
Is there a way to split the string by word while still retaining and visually displaying the line breaks (possibly with CSS using white-space: wrap;
or pre-wrap
)?