To use dot notation in iteration, you must know the property name ahead of time. This means that dot notation cannot directly use variables or dynamic property names because it expects a literal string representing the property name.
However, you can still loop through an object and use dot notation if the property names are known and fixed. Here's how you can use dot notation in iteration for known property names.
In JavaScript, dot notation expects the exact property name (a literal), not a variable. This is why person.key won't work. It looks for a property called key inside the object, which doesn’t exist.
However, bracket notation works because the variable key is evaluated and used as the property name.