Javascript String indexOf(re, ndx = 0)

Description

Javascript String indexOf(re, ndx = 0)


String.prototype.indexOf = function(re, ndx = 0){
  if (typeof re === 'string') {
    re = new RegExp(re, 'g');
  }/* w ww .  j av  a2s . co  m*/
  const s = re.toString();
  if (s[1] === '^') ndx = 0;
  const x = re[Symbol.search](this.slice(ndx));
  return x < 0 ? -1 : x + ndx;
};



PreviousNext

Related