Learn Advanced Array Methods by Building a Statistics Calculator - Step 27

So in theory this code should work?

array.forEach((el) => {
  if(counts[el]) {
    counts[el]++;
  } else {
    counts[el] = 1;
  }

This was my first code, tested both and they both work,
Just to clarify things, is it me who is not understanding something, or is this step broken?