Imagine you’re creating a list of your favorite songs. Instead of writing each song on a separate note, it would be much easier to keep them all together in one place. Similarly, in JavaScript, it wouldn’t be efficient to store each song title in a separate variable. Instead, we can use arrays and objects, which allow us to store multiple pieces of related data in a single variable. These powerful tools help organize and manage data more effectively. Let’s explore how they work!
By the end of this lesson, you'll be able to:
We’ve learned how variables are used to temporarily store and remember data. But say we’re dealing with multiple variables. Then what do we do? For instance, say we’re creating a grocery list of items we need for a fruit salad. We could declare each of the items individually. This would kind of be like writing each item on our list on a different sheet of paper. It would probably be easier and make more sense to just have it all in one place. We can do the same thing with variables using arrays. An array is a list of values contained within brackets and separated by commas. Each value in the array is called an element. Just as we might refer to an item on a grocery list by its placement, the same is true for the elements in an array. However, instead of starting at one, we start at zero. We’ll get into all of this in depth later on. For now, just remember that when we’re dealing with the variable salad, arrays can help us keep all of our ingredients in one place.