 My name is Brendan Reville, I'm from Australia and I learnt to programme when I was 10 years old. Since then I've worked on the Xbox team and now here at Code.org I've helped build some of the hour of code tutorials that I know a lot of people have enjoyed. Whether you're planning out your day, brainstorming ideas for a project or choosing songs for a party, you'll probably want to make a list. Lists help us stay organised by ordering all the relevant pieces of information one after the other in a single place. The same principle applies when we write programmes that include many pieces of related information. Variables are useful for holding a single piece of information. But as we collect more information, keeping the variables organised can be complicated and cumbersome. For example, what if you wanted to keep track of everybody's name in class or an entire school? It's impractical to create hundreds or thousands of individual variables and impossible if you don't know how many items should be tracked ahead of time. In programming, a list is a container used to keep similar pieces of data organised in one place. You can think of it like a container that grows or shrinks to fit the number of items it has inside. The main items you can do to a list are add or replace items, access items and remove items. In JavaScript, a list is called an array. You may hear list or array used interchangeably, but we'll refer to it as a list to keep it simple. A basic example of a list would be all your contacts, on your phone, in your email, etc. Let's see how this would work. To start off, you need to create a list. You do this by using square brackets. An empty list looks like this. You can also create a list with some initial values in it. Just write out the values separated by commas inside the square brackets. For example, you can make a list of numbers like this. Or a list of names, as in a contact list, like this. Just like how you can assign a number or a string to a variable, like var x gets 5, you can also assign a list to a variable to use it later, like this. You can think of a list as a container of numbered slots. Each slot can have one value in it. To access an individual item from your list, write out the name of the list and the number of the slot you want to access, like this. This means, give me the item in the list names, sitting in slot number 2. The official term for slot number is index. So we would read names, left bracket, to, right bracket, as names at index 2. You might have noticed that the first index in the list is 0. In programming, we usually start counting at 0, which means that names at index 0 is the first item of the list, and names at index 2 is actually the third item in the list. When your program runs, the computer will look up the current value that lives at the given index of the list, just like the computer looks up the current value of a variable. For example, if you have a list of numbers called numList, you can create an expression like this. varSum gets numList at index 2, plus numList at index 5. The value stored in index 2 is 40, and the value stored at index 5 is 60, so the variable sum is assigned the value 100. You can also assign or update a particular index's value, you refer to the slot the same way. Names at index 0 gets the value Sarah would replace the current value at index 0, just like assigning a new value to a variable. Once you have created a list, you can modify it by adding items, removing items, or inserting items. To add an item to a list, you can use the appendItem function. Let's add kelly to the end of the list of names, like this. appendItemNames kelly. Notice that appendItem is a function that accepts two parameters, the list name and the actual value that you want to add. Appending an item always adds the value to the end of the list. To remove an item, you use, wait for it, the removeItem function. If we want to remove Josh from the list of names, we'd need to know the index where Josh is stored, so we could do this. removeItemNames1 When you remove items, the whole list shrinks and it closes the gap of the item that was removed. Now our list has four items, indexed 0 through 3. Because the list shrank, items that come after the removal point are effectively re-indexed. So if we once knew that kelly was stored at index 4, kelly is now at index 3. This is not a problem, but something to be mindful of. We can also insert items into the middle of the list with insertItem, like this. insertItemNamesToBrook The insertItem function needs three parameters, the name of the list, the index you want the new item to appear at, and the value to insert. Inserting an item grows the size of the list. Similar to removeItem, the items in the list that come after the insertion point will be re-indexed. Because indexes are just numbers, you can put anything in between the square brackets that evaluates to a number, like variables or even arithmetic expressions. For example, let's say we're keeping track of temperature readings in a location with a variable called loke. varLoke gets 3. We can change the value in numList at index loke, like this. numListAtLoke gets 1. One of the benefits of lists is that their length can grow and shrink over the course of a program. But that means it can be useful to find the length of a list at a given point in time. You can get the length for a list like this. numList.length When your program runs, the computer will replace this with the current length of the list. In this case, the length of the list is 6. A potential point of confusion is that even though the length of the list is 6, the last index is 5. This is because we start the indexing at 0. Because lists change size, a common issue in programming with lists is, what's the index of the last element? We typically find out using the expression list.length-1, and you frequently see it used to access the last element of the list like this. numList And in square brackets, numList.length-1. Lists are a very powerful way to store and maintain data in programs. They open a door for us to write programs that use and process lots and lots of information, especially when we don't know ahead of time just how much information needs to be stored. Let's try them out.