Javascript String Prototype Contain

Description

Javascript String Prototype Contain


String.prototype.contains = function(str) {
  if (str && this.indexOf(str) > -1)
    return true;//from  w w w . ja v  a  2 s .  c o m
  else
    return false;
}

let testString = "this is a test from java2s.com";

console.log( testString.contains("java"));  

console.log( testString.contains("a") );



PreviousNext

Related