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)