JS array count elements

Опубликовано: 01 Июль 2025
на канале: Samovar tutorials
3,349
26

How to count JS array elements?
We can use object properties to do that.
All you need are an empty object, forEach method, an arrow function and a logical disjunction operator to initiate values.
We use elements as object property names and increase its value every time we meet it.
That’s all.
Two Mashas, two Petya and single Vasya.