The index of JavaScript :- Geniusofstudent


  • The indexOf() method returns the position of the first occurrence of a specified value in a string.
  • This method returns -1 if the value to search for never occurs.
  • The indexOf() method is case sensitive

  • Code:-


  • <!DOCTYPE html> 
  • <html> 
  •  
  • <head> 
  •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  • </head> 
  •  
  • <body> 
  •  
  •  <h1>indexOf()</h1> 
  •  
  •  <input type="button" onclick="strfun();" value="Get Answer"> 
  •  
  •  <script> 
  •   function strfun() 
  •   { 
  •    var str = "special News"; 
  •    alert(str.indexOf("News")); //'News' is start from 8th position so return 8 
  •  
  •    alert(str.indexOf("s")); //'s' the first character so it return 0 
  •  
  •    alert(str.indexOf("x")); //'z' is not in the text so return -1 
  •   } 
  •  </script> 
  •  
  • </body> 
  •  
  • </html>
  • The index of JavaScript :- Geniusofstudent The index of JavaScript :- Geniusofstudent Reviewed by Network security on June 26, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.