Thursday, July 31, 2014

How can I check if one string contains another substring in JavaScript?

Ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

Example:
var sample = "mytext";
console.log(sample.indexOf("my") > -1);
Output:
 true

No comments:

Post a Comment