Using Arrays to Group Data

Codecademy Team
Use arrays to keep track of your data in an orderly fashion.

Arrays are Lists

We use lists every day to keep track of certain information. Lists are great because they contain information we need and are organized in a specific order. Let’s imagine for a second if we had a recipe, but all the steps to make the recipe were scrambled! What good is the recipe if the order isn’t followed?

Now take a look at the following code:

let friedEgg = ['heat up pan', 'add oil to pan', 'crack an egg into the pan', 'cook until yolk is no longer runny'];

Above, we have a list of ordered steps telling us how to cook an egg. If we needed to, we could edit the list entirely or edit specific parts of the list. In JavaScript, the idea of keeping a “list” of information translates to arrays. Arrays help store values, known as elements. Like lists, arrays also keep track of the order of their elements.

As shown by the friedEgg example, what we actually created is an array. The elements inside are the strings: 'heat up pan', 'add oil to pan', etc… As we dive deeper into arrays, we’ll also cover how to add more elements, retrieve elements, and edit them.

So, if you need to list out your information, look no further than using an array!