Understanding the Array length Property in JavaScript
π Scenario: You are helping a small online store keep track of the items in their shopping cart. Each item is stored in an array. You want to find out how many items are currently in the cart.
π― Goal: Build a simple program that creates an array of items, then uses the length property to find out how many items are in the array, and finally prints that number.
π What You'll Learn
Create an array called
cartItems with exactly these items: 'apple', 'banana', 'orange'Create a variable called
numberOfItems that stores the length of the cartItems arrayPrint the value of
numberOfItems to the consoleπ‘ Why This Matters
π Real World
Arrays are used everywhere in programming to store lists of things like shopping cart items, user names, or messages.
πΌ Career
Knowing how to use arrays and their properties like <code>length</code> is a basic skill for any JavaScript developer.
Progress0 / 4 steps