统计字符串中某个字符的个数

 1 <!DOCTYPE html>
 2 <html>
 3 <body>
 4     <title>统计字符串中某个字符的个数</title>
 5     <script>
 6         var countryList=["one","two","three","four","five","six"];
 7         var count=0;
 8         document.write("在以下字符中:<br/>");
 9         for(var i in countryList){
10             document.write(countryList[i]+" ");
11             if(countryList[i].indexOf("o")!=-1)
12             count++;
13         }
14     document.write("<br/> 字符o有"+count+"个。");
15     </script>
16 </body>
17 </html>

posted @ 2018-10-29 20:48  Yuki-Lan  阅读(463)  评论(0编辑  收藏  举报