let string = "foo",
substring = "oo";
string.includes(substring);
// true
let string = "food",
substring = "d";
string.indexOf(substring); // 3
string.indexOf(substring) !== -1; // true
!!~string.indexOf(substring); // true
let string = "food",
expr = /d/;
string.search(expr); // 3
let string = "foo",
substring = "oo";
_.includes(string, substring);
let string = "foo",
expr = /oo/; // no quotes here
expr.test(string); // true
let string = "foo",
expr = /oo/;
string.match(expr);
// ["oo", index: 1, input: "foo", groups: undefined]
- Performance tests are showing that
match and includes might be the best choice, if it comes to a point where speed matters.