var str="Rome was not built in a day"; var count=0; document.write(str+"<br>") str =str.replace(/\s/g,""); for(var i of str){ count++ } document.write("长度:"+count)