欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

es6 includes(), startsWith(), endsWith()

发布时间:2023/12/2 编程问答 57 豆豆
生活随笔 收集整理的这篇文章主要介绍了 es6 includes(), startsWith(), endsWith() 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

传统上,JavaScript 只有

indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中。ES6 又提供了三种新方法。

  • includes():返回布尔值,表示是否找到了参数字符串。
  • startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
  • endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
let s = 'Hello world!';s.startsWith('Hello') // true s.endsWith('!') // true s.includes('o') // true

 


更多专业前端知识,请上 【猿2048】www.mk2048.com

总结

以上是生活随笔为你收集整理的es6 includes(), startsWith(), endsWith()的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。