arrays
In this module we'll study arrays.
Location Check
Let's get you where you gotta be:
Description
An array is a numerically indexed map of values. Starting out, it's easier to just say it's a great way to collect a bunch of values together. They allow us to collect things like names, usernames, product names, prices, etc.
Sample Code
Add these arrays to the file:
Take a minute and think about this:
Read the above examples, what do you think are some general rules about arrays?
Key Points
Here are some key points:
An array is created like a variable.
It can be named anything.
We use square brackets
[]
to collect values.We separate items with commas in the brackets.
We can have a collection of one type(6 strings that are zombie movies).
We can also collect multiple types:
The 0 index
An important fact that everybody learns when they first start coding:
The index of an array starts at 0
Check it out:
Access Values
You can access arrays using bracket notation []. Print some of these array values by naming the array and then naming the index position:
More Practice
Write four different arrays that have 4 values. Print four of the values in console statements. Try this:
Print the first value of the first array. Remember 0!
Print the second value of the second array.
Print the third value of the third array.
Print the fourth value of the fourth array.
If you can't get that, just create some arrays and print what you can. Just play around and figure out what you can. There are also some great ways to go learn online. Just Google it.
Last updated