6.6 检查子串

有三个方法用于检查某个字符串是否是另一个字符串的子串:

> 'hello'.startsWith('hell')
true
> 'hello'.endsWith('ello')
true
> 'hello'.includes('ell')
true

每个方法都有可选的第二个参数,用于指定字符串搜索的开始或者结束位置:

> 'hello'.startsWith('ello', 1)
true
> 'hello'.endsWith('hell', 4)
true

> 'hello'.includes('ell', 1)
true
> 'hello'.includes('ell', 2)
false

results matching ""

    No results matching ""