Search⌘ K
AI Features

Discussion: The Grocery List

Explore how JavaScript arrays store elements and additional properties without affecting the array's length. Understand why properties added to arrays do not count as elements and cannot be iterated by array methods, helping you write clearer, bug-free code.

Verifying the output

Now, it’s time to execute the code and observe the output.

Javascript (babel-node-es2024)
const groceryList = [];
groceryList[0] = "Bread";
groceryList[1] = "Milk";
groceryList.user = "John";
console.log(groceryList.length);
...