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.