Arrays: Ordered Lists

Learn how to store multiple values in a single variable using arrays — JavaScript's ordered, numbered lists.

Step 1 of 5

One variable, many values

So far, each variable has held a single value — one name, one score, one boolean. But what if you need to store a list of things? A playlist of songs, a class roster of student names, a shopping cart of items? You could create separate variables (`song1`, `song2`, `song3`...), but that quickly becomes unmanageable.

Arrays solve this problem. An array is an ordered list of values stored in a single variable. You create one with square brackets `[]`, placing values inside separated by commas. Arrays can hold any type of data — strings, numbers, booleans, even other arrays.

Think of it this way: An array is like a row of numbered mailboxes in an apartment lobby — each box has a number (starting from 0), and you can put something in, take something out, or check what's there. The mailboxes stay in order, and you refer to each one by its number.
Web Standard
JavaScript arrays are actually a special type of object. Unlike arrays in some other languages, JavaScript arrays can hold mixed types (strings and numbers together), grow and shrink dynamically, and have no fixed size. They are one of the most commonly used data structures in all of programming.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...