Asked by Sohail · · 2 answers
In ECMAScript 6 has String.prototype.includes
:
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
Old browsers do not support includes
. So for old browsers use String.prototype.indexOf
that returns -1
if a substring not found:
var string = "foo";
var substring = "oo";
console.log(string.indexOf(substring) !== -1);
0
0