Check whether a string contains a substring - Javascript String Operation

Javascript examples for String Operation:String Search

Description

Check whether a string contains a substring

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. j  a  v  a  2s .  c  o  m*/
String.prototype.contains = function(test) {
   return this.indexOf(test) == -1 ? false : true;
};
var string = "asdf";
console.log(string.contains("as"));
    }

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

Related Tutorials