JSFiddle - React, Tailwind, and code Playground

JavaScript

var div = document.createElement('div');
var text = document.createTextNode('test\ntest2\ntest3');
div.appendChild(text);
alert((div.innerHTML.match(/\n/g)!==null) ? div.innerHTML.match(/\n/g).length : 'There is no line breaks');