小编git*_*ole的帖子

计算布尔值数组中的真实成员数

javascript的新手,我无法计算布尔值数组中的trues数.我正在尝试使用reduce()函数.有人能告诉我我做错了什么吗?

   //trying to count the number of true in an array
    myCount = [false,false,true,false,true].reduce(function(a,b){
      return b?a++:a;
    },0);
    alert("myCount ="+ myCount);  // this is always 0
Run Code Online (Sandbox Code Playgroud)

javascript arrays reduce ternary-operator

18
推荐指数
4
解决办法
1万
查看次数

标签 统计

arrays ×1

javascript ×1

reduce ×1

ternary-operator ×1