开发学院

您的位置:首页>教程>正文

教程正文

ES6 新的String对象方法endsWith

ES6 新的String对象方法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