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 为索引
上述代码的输出将如下所示 −
true true