augment.js icon indicating copy to clipboard operation
augment.js copied to clipboard

Can we add string.include method?

Open hk-skit opened this issue 8 years ago • 2 comments

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

hk-skit avatar Mar 23 '16 05:03 hk-skit

It is possible to use String.prototype.indexOf() instead: str.indexOf(searchValue[, fromIndex]) with the same effect

plugn avatar Mar 25 '16 10:03 plugn

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.

hk-skit avatar Mar 29 '16 04:03 hk-skit