Sample Video Frame

Created by Zed A. Shaw Updated 2024-02-17 04:54:36
 

17: Sequences and For Loops

Most programming languages have some way to store data inside the computer. For some languages that storage is just raw memory locations, but programmers easily make mistakes when that's the case. In modern languages you're provided with some core ways to store data called "data structures". A data structure takes pieces of data (integers, strings, and even other data structures) and organizes them in some useful way. In this exercise we'll learn about the sequence style of data structures called a "list" or "Array" depending on the language.

JavaScript's simplest sequence data structure is the Array which is an ordered list of things. You can access the elements of an Array randomly, in order, extend it, shrink it, and most anything else you could do to a sequence of things in real life.

You make an Array like this:

let fruit = ["apples", "oranges", "grapes"];

That's all. Just put [ (left-square-bracket) and ] (right-square-bracket) around the Array of things and separate them with commas. You can also put anything you want into an Array, even other Arrays:

let inventory = [ ["Buick", 10], ["Corvette", 1], ["Toyota", 4]];

In this code I have an Array, and that Array has 3 Arrays inside it. Each of those Arrays then has a name of a car type and the count of inventory. Study this and make sure you can take it apart when you read it. Storing Arrays inside Arrays inside other data structures is very common.

Previous Lesson Next Lesson

Register for Learn JavaScript the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.