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 文章被收录于专栏

前端技术分享

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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