indexOf() and lastIndexOf() using Strings in Javascript

indexOf() and lastIndexOf() using Strings in Javascript


<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<script type="text/javascript">

//indexOf will return the index of the word we search in the entire string

var str= "HELLO TO WORLD WELCOME TO THE NEW GENERATION!!";

var b= str.indexOf("TO");
console.log(b);

//lastIndexOf will search for the word from the end of the string 

var c= str.lastIndexOf("TO");
console.log(c);


</script>

</head>
<body>
<h1></h1>
</body>
</html>





Comments

Popular posts from this blog