I know we've mentioned array's quite a few times within the previous lessons, and we finally got to
them and we are saving the best till last because arrays are really, really cool.
I'm going to show you what they are and how you can use them.
So just like objects, they give us the ability of a single variable and assign a bunch of values to
it so that we can reference those values just with a single variable.
So in this case, we've got shopping, but all of the contents of shopping, we have access to all that
full list and then we can update change it as needed.
We can also contain objects within arrays, arrays within arrays, so it can get fairly complex.
We can use all the different data types as we've seen before, where we're using strings, we're using
booleans numbers, null, undefined.
So all of them are valid and they can all sit within the array in order to get valid values from the
arrays.
So they are zero based index values.
So unlike what we saw with objects, arrays are limited to using the index value in order to retrieve
back whatever value index value is associated with it.
So we've got an example here where we're using the list we're referencing.
We're trying to pull back item number three in the list, and that's where we're pulling back.
So remember, it's starting at zero.
So number three would be 35.
And you can see that zero is Lowrance.
One speaks to is true, three is 35.
So using the array name and the index value, that's how we can retrieve values that are contained within
that array.
So the challenge for this lesson is to create an array with different types of data and then return
the values of those different data types.
So get the value into the console of the below array.
We've got the default array called the list and there's a combination of that.
There's an object in there.
There's another array in there, there's a number.
So there's all these different values that are contained in there.
So the objective just to try it out and get 55 out, get to out, see how many times it takes you in
order to retrieve back that information.
And as you can see, two is a little bit tricky there.
So this is going to be a little bit more of a challenge to put in the console.
You can pause the video and I'll show you the solution coming up.
And as well, this is a quick sneak peek at the solution will list out the list.
And you can see that all of that information is contained.
So what we want it to do is retrieve back some of the values that are contained in here.
And in particular, we were looking to retrieve back 35 and number two there and also retrieve back
55.
So we want to get 55 and two.
So those are two of the more complex ones, because the first one is contained within the object and
the second one is contained within the array.
So let's try it out within the console.
And as you can see, when you are using the list, you can get the values back from the list.
So using the index value so you can retrieve back the first first one.
So zero based.
Remember that.
And then the second one is one.
And you can go all the way through the entire list until you get to the one that you want to see.
So if we were to list number six, this is where we retrieve back that object.
So we've got a choice here where to retrieve back the score 55.
We can use the list just as we set it, but we want to get score back.
So we've got two choices because we've got an option to do it as a dot notation or a bracket notation.
And as you can see, they're going to return back.
So either one of these is correct.
And let's type this into the console.
So either one of these was a correct way to retrieve it back.
And then the other object or another value that we want to retrieve back is coming from the list.
And this one is going to be contained in number seven.
And as you can see, this is an array that's contained within the array.
So in order to retrieve back, the format is the same.
So if we want to retrieve the second item, we do one.
So retrieving it is the same way.
And sometimes it does get fairly complex because you have to really dig through these and you'll see
instances of arrays that contain objects and then objects that contain arrays again so they can get
fairly complex.
So it is important to practice and try it out and just make sure that you are able to retrieve back
any one of the values contained within the list.