WEEK: 13
Active: November 9th - November 15th
Work Due: November 16th @ 11:59PM

What are Arrays

What is an array? I remember when I first started programming, this was one the most interesting, but somewhat tricky things to get my head around. So, I am going to try to explain a written description, pictorial one, and code-based one.

An array is a collection of like items. For example, if you think your music collection, you may have playlists (if you have Spotify), or you may have created your playlist from the music you own. Those playlists represent an array of songs. Be mindful we usually don’t mix our songs with say a movie playlist. It doesn’t typically make sense. That is an array of like items.

What does it look like in a picture?

Array Image

Notice the groups? There are apples, trucks, and cubes, and are not mixed. That is how arrays work. So, you can think of it as an array of apples and only apples, and so on.

How do we do this in code?

    function setup()
    {
        var myNumbers = []; 

        var myApples = ['Fuji','Golden','Macintosh','Pink Lady'];  // this an array of strings
    }

In the first instance, we are just creating an empty array. We plan on adding only numbers to it (we will look at that later). In the second array, we create an array of apples and put values in it. In this case, we add names of the apples automatically.

Next, let’s look at why? Why do we want to use arrays? Keep in mind that square brackets [ ] make some uncomfortable, so why is it good to go through the effort of learning about them?


Previous section:
Next section: