Code Studio · Level 6
Real JavaScript Arrays
Pack one lunchbox with several foods. An array keeps a whole ordered list inside one JavaScript variable.
What is an array?
An array is like a lunchbox with numbered spaces. One variable holds the whole lunch, while each food has its own index.
Important: JavaScript starts counting at 0, so the first food is lunchBox[0].
[0]

[2]

-
1
Make the list
let lunchBox = ["sandwich", "cookies", "carrots"]; -
2
Grab a slot by number
lunchBox[0]gets the sandwich. The number inside the brackets is called an index. -
3
Run the lunch code
Each
say()command reads one indexed food and packs it into the matching lunchbox space.
Pack a JavaScript lunch.
Example code
let lunchBox = ["sandwich", "cookies", "carrots"];
say(lunchBox[0]);
say(lunchBox[1]);
say(lunchBox[2]);
Run the code to pack lunch.
lunchBox[0]
lunchBox[1]
lunchBox[2]
Lunchbox is empty
- Run your code to see output.
Use the example, then run it to fill all three array slots.
Lunch packed!
You stored three foods in one array and found each one by its index.
Open Array Builder