String.prototype.startsWith()
String 值的 startsWith() 方法确定该字符串是否以指定字符串的字符开头,并根据需要返回 true 或 false。
¥The startsWith() method of String values determines whether this string begins with the characters of a specified string, returning true or false as appropriate.
Try it
语法
参数
¥Parameters
searchString-
要在此字符串开头搜索的字符。不能 是一个正则表达式。所有非正则表达式的值都是 强制为字符串,因此省略它或传递
undefined会导致startsWith()搜索字符串"undefined",这很少是你想要的。 positionOptional-
预计找到
searchString的起始位置(searchString第一个字符的索引)。默认为0。
返回值
例外情况
描述
示例
使用 startsWith()
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-string.prototype.startswith |
浏览器兼容性
BCD tables only load in the browser