欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

includes(),startsWith(),endsWith(),的使用与区别

程序员文章站 2022-03-08 22:50:52
...

includes():返回布尔值,表示是否找到了参数字符串。
startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。

let s ='He1lo world!' ;

s. startsWith( 'Hello') // true
s. endsWith('!') // true
s. includes('o') // true
相关标签: js js