Using the indexOf() Method to Find All Occurrences of the Letter e in a Sentence : String : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » String »

 

Using the indexOf() Method to Find All Occurrences of the Letter e in a Sentence




<html>
<body>
<script type="text/javascript" language="JavaScript1.1">
<!--
  // Declare variables
  var pos = 0;
  var num = -1;
  var i = -1;
  var graf = "This is a test";
   
  // Search the string and counts the number of e's
  while (pos != -1) {
    pos = graf.indexOf("e", i + 1);
    num += 1;
    i = pos;
  }
   
  // Write the response to the page
  document.write(graf+"<br>")
  document.write("There were " + num + " e's in that paragraph.");  document.close();
//-->
</script>
</body>
</html>


           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» String