加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

获取数组中符合条件的值的个数

发布时间:2020-12-17 08:36:12 所属栏目:安全 来源:网络整理
导读:countBy_.countBy(list,iteratee,[context]) Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy,but instead of returning a list of values,returns a count for the number of values in that g
countBy_.countBy(list,iteratee,[context]) 
Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy,but instead of returning a list of values,returns a count for the number of values in that group.

_.countBy([1,2,3,4,5],function(num) {
  return num % 2 == 0 ? 'even': 'odd';
});
=> {odd: 3,even: 2}


引用地址:http://underscorejs.org/#countBy

自己例子:

const ck = _.countBy(this.handlingUnitMaterials,function (hu) {
      return hu.checked == true ? 'ischecked' : 'nochecked';
    });
返回的ck就是一个对象。自己打印看看即可

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读