jquery 字符串 判断 等-String.prototype.startsWith()

2023-08-26 0 4,612 百度已收录

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 日。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 jquery jquery 字符串 判断 等-String.prototype.startsWith() https://www.wkzy.net/game/165068.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务