JavaScript String Method : search()

The search() method is used to search a specific value in a string. It returns the position of searched value. And if the match would not found on the string then it will return -1. The syntax is :
  string.search("value to search")
Example :
<html>
<body>
  <script>
    var mystr = "This is test String For search Function.";
    document.write(mystr, "<br/>");
    document.write("Search For 'test' : ", mystr.search('test'));
    document.write('<br/>')
    document.write("Search For 'Function' : ", mystr.search('Function'));
  </script> 
</body>
</html>
Output :


Where the position of "test" starts from 8 and the position of "Function" starts from 31.

Next Topic :