代码改变世界

startsWith vs indexOf

2023-12-19 11:34  钟铧若岩  阅读(16)  评论(0编辑  收藏  举报

JS startsWith函数,其参数有 3 个,stringObj,要搜索的字符串对象,str,搜索的字符串,
position,可选,从哪个位置开始搜索,如果以 position 开始的字符串以搜索字符串开头,则返
true,否则返回 false

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