let str = " Hello world " ; str . endsWith ( " world " ) // 返回 true str . endsWith ( " World " ) // 返回 false

尝试一下 »

定义和用法

endsWith() 方法用来判断当前字符串是否是以指定的子字符串结尾的(区分大小写)。

如果传入的子字符串在搜索字符串的末尾则返回 true,否则将返回 false。

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

var str = " To be, or not to be, that is the question. " ; str . endsWith ( " question. " ) ; // true str . endsWith ( " to be " ) ; // false str . endsWith ( " to be " , 19 ) ; // true

尝试一下 »

String 对象参考手册 JavaScript String 对象