startsWith JavaScript · 字符串方法
判断字符串是否以指定子串开头。
怎么用
字符串.startsWith(子串, [起始位置])
小例子
console.log("hello".startsWith("he"));
console.log("hello".startsWith("lo"));
运行结果
true false
提醒:第二个参数可指定从哪个索引开始检查。
官方文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← JavaScript全部词条