ES6 - 新字符串方法 endsWith
此函数确定一个字符串是否以另一个字符串的字符结尾。
语法
str.endsWith(matchstring[, position])
参数
matchstring − 字符串必须以此字符结尾。区分大小写。
Position − 与匹配字符串匹配的位置。此参数是可选的。
返回值
如果字符串以匹配字符串的字符结尾,则为 true;否则为 false。
示例
var str = 'Hello World !!! '; console.log(str.endsWith('Hello')); console.log(str.endsWith('Hello',5));
输出
false true