JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<body>
<
<button onclick="xrun()">Try it</button>
<p>
</p>
</body>
</html>
JavaScript
//find single words in single lines
function xrun(){
var text = "Lorem,"
+ "consectetur adipisicing elit,"
+ "sed do eiusmod tempor incididunt"
+ "ut labore et dolore magna aliqua.";
var words=find_swisl(text);
alert(words);
}
function find_swisl(var multilineText){
//extracting words and sentences
var words=[];
var sentences=[];
for(var i = 0;i < multilineText.length;i++){
//code here using lines[i] which will give you each line
var line=multilineText[i];
var splitw=line.split(" ");
if(splitw.lenght>1){
//this is not single word
words.push(line);
}
else{
//this is single word
sentences.push(line);
}
}
//throwing the word and sentence pack
var div_words="";
for(var x=0;x<words.length;x++){
div_words.concat(x,"<br>");
}
var div_sentences="";
for(var y=0;y<words.length;y++){
div_sentences.concat(y,"<br>");
}
return div_words;
}