String.prototype.startsWith()
startsWith() 方法用于判断当前字符串是否以另一个给定的子字符串开头,并根据判断结果返回 true 或 false。
js
startsWith(searchString)
startsWith(searchString, position)
搜索字符串
要在此字符串开头搜索的子字符串。 不可能。 所有不是正则表达式的值都将被忽略,因此省略它或传递 undefined 将导致startsWith() 搜索字符串“undefined”jquery 字符串 判断 等,这不应该是您想要的。
位置可选
期望找到的searchString的起始位置(即searchString的第一个字符的索引)。 默认值为 0。
如果在字符串开头找到给定字符(包括当 searchString 为空字符串时)jquery 字符串 判断 等,则返回 true; 否则返回 false。
如果 searchString 是,则抛出此异常。
这样您就可以确定一个字符串是否以另一个字符串开头。 此方法区分大小写。
js
const str = "To be, or not to be, that is the question.";
console.log(str.startsWith("To be")); // true
console.log(str.startsWith("not to be")); // false
console.log(str.startsWith("not to be", 10)); // true
规格
BCD 表仅在浏览器中加载
发现此页面内容有问题? 想更多地参与吗? 了解如何做出贡献。
此页面的最后修改时间为 2023 年 8 月 10 日。