ES6 - String.prototype.startsWith()



它確定字串是否以指定字串的字元開頭。此函式返回 true 或 false。

語法

以下語法適用於String.prototype.startsWith(),其中,searchString 是要在該字串開頭搜尋的字元。position 是一個可選引數。它表示在此字串中開始搜尋searchString 的位置。預設值為 0。

str.startsWith(searchString[, position])

示例

let company='TutorialsPoint'
console.log(company.startsWith('Tutorial'))
console.log(company.startsWith('orial',3)) // 3 is index

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

true
true
廣告

© . All rights reserved.