js 的startsWith和indexof

js 的startsWith和indexof

1. startsWith 函数

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

const str1 = 'Saturday night plans';

console.log(str1.startsWith('Sat'));
// expected output: true

console.log(str1.startsWith('Sat', 3));
// expected output: false

2. indexof 函数

indexof 函数可返回某个指定字符串在字符串中首次出现的位置。

JavaScript 文章被收录于专栏

前端技术分享

全部评论

相关推荐

不愿透露姓名的神秘牛友
2025-12-19 10:45
牛客68819587...:按照品喜喜的时薪 你这就是白菜价 别去奥 别人都是 40-50k *24
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务