LESSON 19
Arrays
Learning objective: Store ordered lists of values in arrays.
Understand
Arrays hold multiple values in one variable.
An array is an ordered list. Each item has an index starting at 0. You can read items by index, get the count with .length, and add items with .push().
Analogy: An array is like a numbered row of lockers, each holding one value.
See It in Action
Creating and reading an array:
const fruits = ["apple", "pear"];
console.log(fruits[0]); // apple
fruits.push("mango");
console.log(fruits.length); // 3How it works:
fruits[0] reads the first item, push adds a new one, and .length reports how many there are.Try It Yourself
- Create an array of three items.
- Read the second item by index.
- Push a new item and log the length.
Quick Quiz
What index is the first array element?
Challenge
Build an array of your goals and log how many there are.
Success condition: Your array stores items and reports the correct length.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →