How to count the values of an array that are equal and put the total number of those elements equal in a message?

0

I want it to show up in my message or in a notification icon that I am doing only the notifications that have status "1"

for (var i = 0; i < data1.length; i++) { // total de los objetos del arreglo 
   if (data1[i].estado == "1") {  // todos los elementos que su estado sea igual a 1
    // Aqui esta mi duda.
   }
}
    
asked by JessússGaarcíaa 07.09.2018 в 20:50
source

2 answers

1

Using filter() is shorter

let arr = [1,2,1,3,45,6,7,8,9,1,3,2,1]

console.log(arr.filter(e=>e===1).length)
    
answered by 08.09.2018 в 00:42
0

It is solved. I had to add a counter nothing more.

var counter=0;
counter++;
$("#id_de_tu_elemento").html(counter);
    
answered by 07.09.2018 в 21:14