The Last index of JavaScript:- Geniusofstudent

  • The lastIndexOf() method returns the position of the last occurrence of a specified value in a string.
  • The string is searched from the end to the beginning, but returns the index starting at the beginning, at position 0.
  • This method returns -1 if the value to search for never occurs.
  • This method is case sensitive.




Code:-

<!DOCTYPE html> 
<html> 
 
<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 
 
<body> 
 
 <h1>lastIndexOf()</h1> 
 
 <input type="button" onclick="strfun();" value="Get Answer"> 
 
 <script> 
  function strfun() 
  { 
   var str = "special News"; 
   alert(str.lastIndexOf("s")); //Returns last matched character '11' 
 
   alert(str.lastIndexOf("f")); //'f' is not found in the given string, so it returns -1 
  } 
 </script> 
 
</body> 
 
</html>
The Last index of JavaScript:- Geniusofstudent The Last index of JavaScript:- Geniusofstudent Reviewed by Network security on June 26, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.