Counting with arrays?

Hey guys!

I have for example this object in my firebase database and i push them into an array.
I am just wondering how could i simply sum the “kiszereles” field and count for example the number of times when the “nev” field’s value is “HALDORÁDÓ TOP Method Feeder - Maximum Green”.

I’d probably do something along these lines:

//kiszereles sum
let kisSum = myArray.reduce((sum, item) => sum + item.kiszereles);

//Number of occurrences of nev
let nevOccurrences = myArray.filter(item => item.nev === 'HALDORÁDÓ TOP Method Feeder - Maximum Green').length;
1 Like

thank you very much! One more question :slight_smile:
How could i make more serious filtering? Like counting all the item.nev, sorting them by number of occurences and showing only the top 3