arr.some()与arr.every();应用场景

arr.some()与arr.every();

// tabledata第一层只要有在selection里面就是全选
      const isSelect = selection.some((el) => {
        const tableDataIds = this.tableData.map((j) => j.spuCode);
        return tableDataIds.includes(el.spuCode);
      });
      // tableDate第一层只要有不在selection里面就是全不选
      const isCancel = !this.tableData.every((el) => {
        const selectIds = selection.map((j) => j.spuCode);
        return selectIds.includes(el.spuCode);
      });
      if (isSelect) {
        selection.map((el) => {
          if (el.children) {
            // 解决子组件没有被勾选到
            this.setChildren(el.children, true);
          }
        });
      }
      if (isCancel) {
        this.tableData.map((el) => {
          if (el.children) {
            // 解决子组件没有被勾选到
            this.setChildren(el.children, false);
          }
        });
      }

其他循环更多用法见:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
arr.indexOf方法用于在数组中查找指定元素,并返回其下标位置。如果找到匹配的元素,则返回元素的下标位置;如果没有找到匹配的元素,则返回-1。这个方法区分大小写,所以对于字符串而言,要确保大小写一致才能正确匹配。 例如,在数组arr中,如果要查找元素'orange',则arr.indexOf('orange')会返回0,表示该元素在数组中的下标位置是0。如果要查找元素'o',则arr.indexOf('o')会返回-1,表示没有找到该元素。同样地,对于数字元素,比如在数组arr中查找元素2016,则arr.indexOf(2016)会返回-1,表示没有找到该元素。 需要注意的是,indexOf方法只返回第一个匹配的元素的下标位置。如果数组中存在多个相同的元素,只会返回第一个匹配的元素的下标位置。 而对于IE8及其以上的浏览器不支持数组的indexOf方法的问题,可以使用其他方法来解决,比如使用polyfill或者使用ES6的语法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Array 的 indexOf方法](https://blog.csdn.net/wdadadadada123/article/details/90702180)[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_1"}}] [.reference_item style="max-width: 50%"] - *2* [ES5-数组API:arr.indexOf、arr.every(条件)、arr.some(条件)、arr.forEach()遍历、arr.map()、filter过滤...](https://blog.csdn.net/weixin_42931345/article/details/106080634)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做个有准备的人

受益虽浅以资鼓励无限

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值