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 is length of string
</script>

上述程式碼的輸出將如下所示:

true
true
廣告
© . All rights reserved.