- 720p
- 540p
- 360p
- 0.50x
- 0.75x
- 1.00x
- 1.25x
- 1.50x
- 1.75x
- 2.00x
We hope you enjoyed this lesson.
Cool lesson, huh? Share it with your friends
About this lesson
What are arrays, and how does JavaScript use them?
Exercise files
Download this lesson’s related exercise files.
Arrays58.7 KB Arrays - Solution
58.9 KB
Quick reference
Arrays
An array is a container that holds many items.
When to use
Anytime you need to contain many items, use an array.
Instructions
Arrays look like this:
var pizza = ["Hamburger", "Cheese", "Mushroom"];
To call an item in the array, we reference its index number:
pizza[1];
Index numbers start with 0.
We can find out how many items are in an array:
pizza.length;
We can sort an array alphabetically:
pizza.sort();
To add more items to an array, use:
pizza.push("Onion");
Hints & tips
- Arrays are containers that can hold many things
- Index numbers start at 0
- pizza.length to get the length of an array
- pizza.sort() to sort an array
- pizza.push("Add something") to add an item
Lesson notes are only available for subscribers.