Accepting an array as the first parameter to String.prototype.includes

Andrea Giammarchi andrea.giammarchi at
Tue Mar 10 19:57:26 UTC 2015

I'm still having hard time understanding what's the difference between
contains and the good old indexOf beside the RegExp check ... but I agree
having multiple explicit searches instead of multiple implicit searches
won't make such big difference. Good news is, you probably will still use
RegExp anyway because names can be composed and haveing a \bName\b helper
is probably what you might need anyway :-)

i.e. Maria !== Marianne

On Tue, Mar 10, 2015 at 3:31 PM, Bergi <a.d.bergi at> wrote:

> Edwin Reynoso wrote:
> > There are times where I would like to check whether a string has every
> > occurrence of certain strings/numbers:
> >
> > Now to achieve what I would like `String.prototype.includes` to
> accomplish
> > with an array as the first parameter, I currently take the following
> > approach:
> >
> > var str = "John,Mary,Bob,Steve";
> > var names = ["Mary", "Bob"];
> > names.every(name => str.includes(name)); // true;
> And that's perfectly fine imho, pretty expressive about what is done about
> the array. Just passing an array to `.includes` is rather meaningless (not
> denotative).
> If we need a method to do this (to allow for native optimisations with
> fancy string search algorithms), I'd suggest to use a different method name
> like `String.prototype.includesAll`.
>  Bergi
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list