search between a range of characters using String indexOf - Javascript String

Javascript examples for String:indexOf

Description

search between a range of characters using String indexOf

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w w  w  .jav  a2 s .  c  o m

var myText = "abab";
if (myText.indexOf("ab") === 0) {
    console.log('starts with', 'ab');
    if (myText.indexOf("ab", 2) === 2) {
        console.log('followed by', 'ab');
    }
}

    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials