var str ="Rome was not built in a day"; arr =str.replace(/\s/g); var geshu=0; for(var i of str){ geshu++; } document.write(geshu);