Welcome to my website, have a nice day!
Dream it, Do it, Make it!

JS判断字符串是否以指定字符开头

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

语法

str.startsWith(searchString[, position])

参数:

  • searchString:要搜索的子字符串。

  • position:可选,包含该值,在str中搜索searchString的开始位置,默认值为0,也就是真正的字符串开头处。

##示例

"www.4spaces.org".startsWith('4spaces',4);//true
赞(0)
未经允许禁止转载:Ddmit » JS判断字符串是否以指定字符开头

评论 抢沙发

登录

找回密码

注册