There are times where I would like to check whether a string has every occurrence of certain strings/numbers:
``` var str = "John, Mary, Bob, Steve"; str.includes(["Mary", "Bob"]); // true var str2 = "John, Mary, Steve"; str2.includes(["Mary", "Bob"]); // false ``` So the way the above would work would be as an AND operation. Meaning having all of the instances of the array past in. To use `String.prototype.includes` as an OR operation with the first parameter being an array, wouldn't be necessary because you can use a regular expression for that: ``` var str = "John, Mary, Bob, Steve"; (/Mary|Bob/g).test(str); // true var str2 = "John, Mary, Steve"; (/Mary|Bob/g).test(str2); // true ``` As of right now `String.prototype.includes` called with an array as the first parameter will call `.toString()` on the array resulting in the following: ``` var str = "Hello World"; str.includes(["Hello", "World"]); //false because it calls ["Hello", "World"].toString() == "Hello,World"; ``` Pretty useless!!! 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; //Or perhaps make it a function: function stringIncludes(str, names) { if(names) { return names.every(name => str.includes(name)); } return false; } Thanks.
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss