...

Array Length Property

Arrays have a special property called length that tells you how many items are in the array. You can access it like this:

let fruits = ["apple", "banana", "cherry"];
console.log(fruits.length);  // 3

The .length property is incredibly useful. It lets you:

  • Check if an array is empty (array.length === 0)
  • Know how many items you're working with
  • Display counts to the user

The length updates automatically as you add or remove items from the array.

Your Task

You're packing a suitcase for a trip. The code asks if you want to pack three different items. At the end, print the length of the suitcase array to see how many items you packed.

Variables

No variables

Loading...

Output (Console)