字符串查找类

接下来介绍一些可以通过 ES5 PolyFill的方法,但是现在 ES6 原生实现了

Method    Param    Return    Description
includes()    需要验证是否被包含的字符串    Boolean    表示是否调用此方法的字符串是否包含参数中的字符串
startsWith()    需要被验证的字符串    Boolean    表示调用此方法的字符串的开头部分是否就是参数
endsWith()    需要验证的字符串    Boolean    与 startsWith 类似,不同点此方法为结尾
下面看一下例子:

let name = 'hello,this is Hao!';
name.startsWith('hello');
// true
name.endsWith('!');
// true
name.includes('this');
// true

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-07-20
  • 2021-05-20
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-01-08
  • 2022-01-17
  • 2021-09-17
相关资源
相似解决方案