augment.js
augment.js copied to clipboard
Can we add string.include method?
As described here Mozila doc, there's a method string.includes to check whether a string contains searchString or not.
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
We should also add this in augment.js
It is possible to use String.prototype.indexOf() instead: str.indexOf(searchValue[, fromIndex]) with the same effect
Yeah we can achieve the same with it but the thing is that every time we need to check whether the index is not equals -1.