Why javascript contains property is not working in chrome browser? I have tried that Contains Property in javascript.It is working fine in Mozila Firefox Browser. But It is
Actually String.contains
is not supported in Chrome as per the MDN
Here's the way to resolve the issue:
Polyfill
You can easily polyfill this method :
if (!('contains' in String.prototype)) String.prototype.contains = function (str, startIndex) {
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
};
var ClearFilterValue = 'family Schools';
if (ClearFilterValue.contains("family") == true) {
alert('Success');
}
Demo: Fiddle