Using Arrays to Group Data
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!
Author
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Arrays
Like vectors, the array is a data structure used in C++ to store a sequential collection of elements. Unlike vectors, its size cannot be changed. - Article
Arrays
Use this article as a reference sheet for JavaScript arrays. - Article
Javascript Guide: Arrays
Use this guide to brush up on interacting with JavaScript arrays.
Learn more on Codecademy
- Free course
Learn C: Arrays and Strings
Sharpen your programming skills by learning how to create, assess, and modify arrays and strings in C.Beginner Friendly2 hours - Free course
Learn C#: Arrays and Loops
Learn how to organize data and automate repetitive tasks with arrays and loops.Beginner Friendly3 hours - Free course
Learn PHP: Arrays and Loops
Learn how to use for-loops and while-loops to execute the same code multiple times.Beginner Friendly3 hours