xxxxxxxxxx
const array = [1, 2, 3, 5, 2, 5, 9, 8, 3, 5, 2, 5].reduce((count, value) =>
(value == 5 ? count + 1 : count), 0) // --> 4
xxxxxxxxxx
let strxx=[ 'B', '_', 'R', 'R', 'B', 'R' ];
let strxy=strxx.reduce((acu,item)=>
{
acu[item]=(acu[item]||0)+1;
return acu;
},{}); // if you wont objec {}, if you wont array []
console.log(strxy);//{ B: 2, _: 1, R: 3 }