![Modern JavaScript Web Development Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/54/36699054/b_36699054.jpg)
上QQ阅读APP看书,第一时间看更新
Searching in strings
There are new functions to determine whether a strings starts with, ends with, or includes a given string. This can give you much relief from using indexOf(...) and length-related calculations:
"Hello, there!".startsWith("He"); // true
"Hello, there!".endsWith("!"); // true
"Hello, there!".includes("her"); // true
Each of these methods has a position as an optional second parameter, which specifies where to do the search; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith, and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes for more information.