startsWith()
作用:用来判断当前字符串是否以另外一个给定的字符串开头,并根据判断结果返回true / false
语法: str.startsWith(searching, position)
参数说明:
searching
要搜索的子字符串
position
可选 在str中搜索searching的开始位置,默认值为0,也就是字符串的开头位置
注意: position < 0, 默认值为0,从字符串的开头位置开始查找 position > str.length,直接返回false
返回值: Boolean(true / false)
endsWith()
作用:用来判断当前字符串是否以另外一个给定的字符串结尾,并根据判断结果返回true / false
语法: str.endsWith(searching, position)
参数说明和返回值同startsWith()
includes()
作用:用于判断一个字符是否包含在另一个字符串中,根据情况返回true / false
语法: str.includes(searching, position)
参数说明和返回值同startsWith()