OK we'll come back.
So it's time for a few javascript array exercises the way that this works.
There's two exercises in both of them.
I give you some code.
All you need to do is evaluate what happens when this code is run.
So here's the first one.
Go ahead take a look.
Pozza video if you need to and I'll go over the solution and just a few seconds.
OK.
So this one is a little bit tricky.
We start by defining a numbers array.
It has five numbers in it.
And then we're printing out something from the numbers array numbers bracket numbers hotlink.
So numbers that length in this case is 5 1 2 3 4 5 items.
So we're going to access numbers bracket 5 which is a problem because the greatest index in this array
is actually 4.
We start at 0 1 2 3 4.
So numbers 5 doesn't exist.
So what we actually get is undefined and I'll show that to you.
Paste this in the con. And we get undefined.
Just like if I tried to do numbers of 100 that definitely doesn't exist and I get undefined.
So if I do numbers of 5 I get undefined or do numbers of I get 88 so I want to a little bit tricky.
So here's the second exercise positivity if you need to evaluate the code and then we'll go over solution
and just a few moments.
So this one looks a little bit scarier.
We have nested arrays.
So this outer array called friend groups has three items and each one is actually its own array.
So this is what we call nested arrays or a two dimensional array because we're nesting in array instead
of another array.
So each one is three strings long three different friend groups from Harry Potter and I'm con. that
logging friend groups.
The third item index of 2.
So that's going to retrieve this whole array right here.
And then we're finding the first item index zero in that array which is Mouni.
So I'm going to copy this into my console and demonstrate that if I look at friend groups of two that's
going to give me this last friend or peer.
And then if I take that and I get the zero index of that I get the first item which is Mouni.
So this is pretty common to need to burrow into an array and then another array to have some nested
data where we have to access the first layer.
Friend groups to which then gives us this and then we have to then access that with index zero to get
money out when we get to some more complicated data structures like the data that the Facebook API gives
us or the data that comes from our Mongo DB database.
Well need to burrow down into nested arrays to access our data.
All right so that's it for these quick exercises