JSFiddle - React, Tailwind, and code Playground
HTML
<textarea>what ever paragraph words herehcggggggggggggggggggggggggggggggggggggg </textarea>
JavaScript
$(document).ready(function(){
var count = 0;
function fn(){
count++;
return ' ';
}
var x= $('textarea').text().trim();
console.log(x);
x= x.replace(/[\s]+/ig,fn);
var words = count+1;
count = 0;
console.log(x);
});