1、判断一个数组中是否包含某元素

arr.indexOf(val) > -1 //  1包含   -1不包含
arr.includes(val) // ES7 true 包含  false 不包含

2、判断一个字符串中是否包含某字符

str.indexOf(res) != -1 // str 存在的字符串(长的) res 验证的字符串(短的) true 包含 false 不包含
str.search(res) != -1 // str 存在的字符串(长的) res 验证的字符串(短的) true 包含 false 不包含

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案