js includes

1.判断数组/字符串 里是否包含某元素 ,包含返回true, 不包含返回false

2.接受两个参数  第一个参数是要查找的元素,第二个参数是从哪个索引开始查找

3.区分大小写(===)

      const arr = [1, 2, 3, 4, 5];
      console.log(arr.includes(1)); //true
      console.log(arr.includes(6)); //false
      console.log(arr.includes(2, 2)); //false
      console.log(arr.includes(2, 1)); //true

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
includes()方法JavaScript中是用来判断一个数组或字符串是否包含指定的值的方法。它返回一个布尔值,如果包含该值则返回true,否则返回false。这个方法的用法和语法在不同的引用中有略微的差异。 在引用中,使用了数组的includes()方法来判断一个数组是否包含给定的值。例如,中,同样是使用了数组的includes()方法来判断数组是否包含某个值,不同之处在于多了一个参数来指定从数组的哪个索引开始判断。例如,中,介绍了字符串的includes()方法。它与数组的includes()方法类似,用来判断字符串是否包含指定的子字符串。例如,在字符串"Hello world, welcome to the Runoob"中使用str.includes("Runoob")会返回true,因为字符串中包含子字符串"Runoob"。 需要注意的是,includes()方法在判断字符串是否包含子字符串时是区分大小写的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [JavaScript includes() 方法的作用](https://blog.csdn.net/weixin_64103049/article/details/127692464)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [javascript中in和includes的区别](https://blog.csdn.net/qq_44606064/article/details/109545569)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值