WEBVTT

00:00.380 --> 00:08.790
In this lesson we'll be covering a new concept which is that if I raise an array is a list of elements

00:10.350 --> 00:12.450
those elements can be of any kind.

00:12.450 --> 00:15.300
You can have numbers.

00:15.300 --> 00:18.160
True or false letters.

00:18.980 --> 00:21.560
And it's an ordered list.

00:21.700 --> 00:28.770
So each element within within the list has a number associated to it and the index which starts from

00:28.770 --> 00:29.730
zero.

00:29.730 --> 00:38.580
So this is the element 0 element 1 2 3 and 4 and there are two ways of defining an array.

00:38.820 --> 00:40.710
One of them can be like this.

00:40.700 --> 00:51.270
What I've done with square brackets and an equivalent way of defining an array is providing a new array

00:52.710 --> 00:57.540
and then inside the brackets right all the elements say mass.

00:57.660 --> 01:03.970
As you wrote them with the other notation.

01:04.000 --> 01:10.960
So let's take a look at the console to see what we get.

01:11.240 --> 01:13.430
And when I put this in a different variable

01:17.630 --> 01:23.880
when I read of the page to show you see that we have we get the same thing in both cases.

01:24.350 --> 01:26.800
It's a list of elements.

01:26.900 --> 01:31.010
Each element has an order has an index associated to it.

01:31.010 --> 01:36.040
Now how can we access the element that a certain element from this list.

01:36.290 --> 01:37.940
Well that's fairly simple.

01:37.940 --> 01:42.600
Say that I want to grab this element here.

01:42.830 --> 01:49.390
So that element is in position too because it starts from 0 0 0 1 2.

01:49.510 --> 01:53.900
I want to grab the element of position 2 from this list.

01:53.900 --> 01:58.870
So I just have to write the square brackets on the index.

01:58.870 --> 02:00.360
In this case index.

02:00.740 --> 02:03.870
Let's check that out you know konsole

02:06.630 --> 02:12.100
and that's how you can get an element from a certain index.

02:12.140 --> 02:20.090
You can also modify elements from this list say that we want to change this element here from true to

02:20.090 --> 02:23.810
false.

02:24.020 --> 02:26.440
I just need to find out what the index is.

02:26.690 --> 02:30.470
So it's 0 1 2 3.

02:31.520 --> 02:37.240
I can refer to it like this and then I can just change its value to something else.

02:40.430 --> 02:43.190
Let's check that out.

02:43.190 --> 02:46.810
See that we changed that particular value.

02:46.820 --> 02:56.240
Now if we try to access an element that doesn't exist for example I want to access an element located

02:56.240 --> 03:04.770
in an index handwrote you're going to get what's called undefined.

03:04.820 --> 03:12.450
So that's basically telling you that that particular element does not exist in your array.

03:12.460 --> 03:23.260
So race are really important data structure in javascript and in many other programming languages they

03:23.270 --> 03:29.170
allow you to keep a list of elements and those elements those variables can be of different types that

03:29.180 --> 03:31.670
don't need to be of the same type.

03:32.770 --> 03:35.170
And all of them you can.

03:35.390 --> 03:40.700
You can find them by by their index the index always starts from 0.

03:40.700 --> 03:42.700
Don't forget that it doesn't start from 1.

03:42.740 --> 03:44.940
Start from zero.
