0
点赞
收藏
分享

微信扫一扫

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


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}


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


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

自己例子:

const ck = _.countBy(this.handlingUnitMaterials, function (hu) {
return hu.checked == true ? 'ischecked' : 'nochecked';
});


返回的ck就是一个对象。自己打印看看即可

举报

相关推荐

0 条评论