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.