ES6 - 新的字符串方法 endsWith



此函数确定字符串是否以另一个字符串的字符结尾。

语法

str.endsWith(matchstring[, position])

参数

  • matchstring − 字符串必须以其结尾的字符。区分大小写。

  • Position − 匹配 matchstring 的位置。此参数是可选的。

返回值

如果字符串以匹配字符串的字符结尾,则为true;否则为false

示例

var str = 'Hello World !!! '; 
 
console.log(str.endsWith('Hello')); 
console.log(str.endsWith('Hello',5));

输出

false 
true 
广告

© . All rights reserved.