这里有一个可用方法列表:

  1. (ES6) includes
var string = "foo",
    substring = "oo";
string.includes(substring);
  1. ES5 and older indexOf
var string = "foo",
    substring = "oo";
string.indexOf(substring) !== -1;
String.prototype.indexOf returns the position of the string in the other string. If not found, it will return -1.
  1. search
var string = "foo",
    expr = /oo/;
string.search(expr);
  1. lodash includes
var string = "foo",
    substring = "oo";
_.includes(string, substring);
  1. RegExp
var string = "foo",
    expr = /oo/;  // no quotes here
expr.test(string);
  1. Match
var string = "foo",
    expr = /oo/;
string.match(expr);

性能测试表明,如果速度很重要,indexOf可能是最好的选择。