function writeDocument(variable) { document.write(variable + "<br/>"); } var a="Rome was not built in a day"; var aa=a.replace(/\s*/g,""); var sum=0; for(var i of a){ sum++; } writeDocument("字符串中字符的个数:"+sum);