Mega Code Archive

 
Categories / JavaScript DHTML / Data Type
 

Search the string and counts the number of es

<html> <head>    </head> <body>   <script type="text/javascript">   var pos = 0;   var num = -1;   var i = -1;   var myString = "this is a test";      while (pos != -1) {     pos = myString.indexOf("e", i + 1);     num += 1;     i = pos;   }   alert(num + " e");   </script> </body> </html>