ES6 - String.prototype.endsWith() 函数
此函数确定字符串是否以指定字符串的字符结尾,并返回 true 或 false。
语法
下面提到的语法适用于 String.prototype.endsWith(),其中,searchString 是要在此字符串末尾搜索的字符。length 是可选参数。它表示字符串的长度。
str.endsWith(searchString[, length])
示例
<script> let company = 'TutorialsPoint' console.log(company.endsWith('Point')); console.log(company.endsWith('Tutor',5))//5 是字符串的长度 </script>
上述代码的输出将如下所示 −
true true