<!DOCTYPE html> <html> <body> <title>統計字符串中某個字符的個數</title> <script> var countryList=["one","two","three","four","five","six"]; var count=0; document.write("在如下字符中:<br/>"); for(var i in countryList){ document.write(countryList[i]+" "); if(countryList[i].indexOf("o")!=-1) count++; } document.write("<br/> 字符o有"+count+"個。"); </script> </body> </html> 以上