WEBVTT

00:01.750 --> 00:07.900
It's time to talk about next very important aspect, I'm going to discuss what a race are in JavaScript.

00:08.410 --> 00:10.720
eRate is a special type of a variable.

00:11.200 --> 00:13.060
It doesn't store just one value.

00:13.450 --> 00:15.100
It stores a list of values.

00:15.700 --> 00:21.550
Eraser especially helpful when you do not know how many items at least will contain, because when you

00:21.550 --> 00:25.900
create the array, you do not need to specify how many values it will hold.

00:27.010 --> 00:34.540
All right, you create an array and give it a name, just like you would do for any other variable using

00:34.540 --> 00:38.110
the word keyword, followed by the name of the array.

00:38.770 --> 00:44.410
The values are assigned to the array inside a pair of square brackets, and each value is separated

00:44.410 --> 00:45.110
by a comma.

00:45.700 --> 00:49.150
Let's write names, for example, John.

00:51.060 --> 00:54.300
Then Bob and Mary.

00:55.570 --> 01:01.150
In this case, we have an array which consists of three values, but you can pass either strings or

01:01.150 --> 01:07.450
numbers or any data type you would like, you're able to create array with different data types simultaneously,

01:07.450 --> 01:11.470
like strings, numbers, boolean values.

01:12.680 --> 01:14.240
Even erase.

01:15.990 --> 01:23.100
And so on, this technique of creating Erra is known as a right literal, it's usually the preferred

01:23.100 --> 01:24.780
method for creating a race.

01:25.510 --> 01:29.470
As you noticed, we can use a right to store multiple values inside one variable.

01:29.820 --> 01:35.220
This is very convenient and helpful because it allows us to avoid creating multiple variables at the

01:35.220 --> 01:35.790
same time.

01:36.690 --> 01:38.280
Let's log it in council.

01:38.640 --> 01:38.940
Right.

01:38.940 --> 01:40.290
Cancel that lock array.

01:43.120 --> 01:51.250
So here we have our right values in an array are accessed as if they are in a number, at least it's

01:51.250 --> 01:56.860
important to note that the numbering of this list starts at zero and not one.

01:57.610 --> 02:02.710
Each item in an array is automatically given a number, and it's called an index.

02:03.850 --> 02:10.450
This can be used to access specific items in the array, so you see that the first item, John, has

02:10.450 --> 02:18.310
an index number zero, the second item has index one and etc. They said we have for the sixth member,

02:18.310 --> 02:25.660
which is itself an array, and it consists of three values and they are numbered in the same way as

02:25.660 --> 02:25.940
well.

02:27.070 --> 02:33.490
You can also see here a length, which is a property of an array, and it shows us the number of items

02:33.490 --> 02:34.300
array includes.

02:35.020 --> 02:42.580
As you see, the main array consists of six items and the second array consists of three values that

02:42.580 --> 02:49.170
is very useful property, and it's frequently used when we deal with arrays below the property.

02:49.180 --> 02:54.670
You can see underscore, underscore, Proteau, underscore, underscore, but you can just ignore it

02:54.670 --> 02:57.010
because we will talk about it in coming sections.

02:58.570 --> 02:59.050
All right.

02:59.590 --> 03:04.770
In order to access on the specific item of all right, we can do it using index.

03:05.470 --> 03:11.050
So if you need to access, for example, on the first item, John, you need to write the name of the

03:11.050 --> 03:14.830
array and in the square brackets, the index number of the item.

03:15.790 --> 03:21.760
As you remember, a number of the items always starts with zero, so John has the index number at zero.

03:22.780 --> 03:23.830
Let's reload.

03:23.830 --> 03:29.160
And you see we have John in the same way you can access all the other items.

03:29.950 --> 03:32.590
Let's change zero to one and see.

03:32.590 --> 03:39.700
We've got the second item in order to get access on items of array, which is placed inside the main

03:39.700 --> 03:40.070
array.

03:40.510 --> 03:43.590
At first we need to have access on the main array itself.

03:44.290 --> 03:44.530
So.

03:44.530 --> 03:44.800
Right.

03:44.800 --> 03:45.880
Index number five.

03:48.260 --> 03:54.140
So we have accessed on it, right, but in order to access all the item of it, we need to write the

03:54.140 --> 04:00.590
following open and other square brackets and write the index of specific item without.

04:01.070 --> 04:04.130
And you see to which is the second item of the second array.

04:04.850 --> 04:05.360
All right.

04:06.300 --> 04:11.610
As we said, we can pass into any kind of data type and even the functions.

04:12.320 --> 04:13.660
Let's see how to do it.

04:14.360 --> 04:19.200
But before that, let's organize our code, make some white spaces here.

04:20.000 --> 04:26.180
You may remember that JavaScript allows us to use multiple white spaces for better readability.

04:27.610 --> 04:29.560
Then right function.

04:31.280 --> 04:36.710
In this case, we don't need to assign a name to the function because we can call it using variable

04:36.710 --> 04:42.830
name and proper index number, as you remember, this kind of functions are called anonymous functions

04:42.830 --> 04:45.170
because they don't have names.

04:46.140 --> 04:56.820
Let's pass here the parameter name and then inside curly braces, right, return hello, plus name.

04:59.470 --> 05:02.800
At first, let's access on the function itself, right?

05:04.000 --> 05:11.790
Index number six, reload, and we have our function here in order to invoke it.

05:11.830 --> 05:16.030
We just need to add parentheses after the square brackets.

05:16.390 --> 05:24.640
And also as the argument, let's pass the first item of the array, which is John, and which has the

05:24.640 --> 05:25.780
index number zero.

05:27.320 --> 05:32.240
Without and the function is called and the code is executed.

05:32.540 --> 05:33.210
We have here.

05:33.260 --> 05:34.040
Hello, John.

05:35.690 --> 05:36.230
All right.

05:37.530 --> 05:42.870
We can create a race using another method, which is called a right constructor, for that, we need

05:43.020 --> 05:45.340
keyword new, which is an operator.

05:46.350 --> 05:48.570
It's followed by the word array.

05:50.290 --> 05:52.180
Starting with Capital Letter.

05:53.250 --> 05:57.060
And inside the parentheses, we can pass a list of values.

06:00.890 --> 06:03.620
Let's look right in council.

06:06.330 --> 06:10.410
And you see that we have here our newly created a right.

06:12.230 --> 06:18.470
All right, using first method, which was literal notation, is much better than a constructor because

06:18.470 --> 06:23.140
of less typing and also for simplicity, readability and execution speed.

06:23.750 --> 06:25.850
So I recommend all ways to use it.

06:27.370 --> 06:33.170
OK, in this lecture, we have considered what our rights are, how to create them with literal notation

06:33.170 --> 06:34.890
and eRate constructor.

06:35.510 --> 06:38.810
As for the array methods, see you in the next video.
