我是靠谱客的博主 鲤鱼盼望,这篇文章主要介绍【JS基础】startsWith()方法,现在分享给大家,希望可以做个参考。

startsWith()方法

startsWith()方法用来判断当前字符串是否是以另外一个给定的子字符串“开头”的,根据判断结果返回 true 或 false

参数:

str.startsWith(searchString [, position])

searchString
  • 要搜索的子字符串
position
  • 在 str 中搜索 searchString 的开始位置,默认值为 0,也就是真正的字符串开头处

示例:

var 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

最后

以上就是鲤鱼盼望最近收集整理的关于【JS基础】startsWith()方法的全部内容,更多相关【JS基础】startsWith()方法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部