WEBVTT

00:01.260 --> 00:06.390
Let's continue talking about race, we have several functions and JavaScript, which we can use with

00:06.390 --> 00:11.220
arrays, those functions are built in and they are called as array methods.

00:12.360 --> 00:17.970
These methods make arrays more powerful and useful things in JavaScript before we actually demonstrate

00:17.970 --> 00:18.250
them.

00:18.270 --> 00:22.690
I would like to show you how we can change values dynamically in array.

00:23.310 --> 00:29.610
Let's create variable colors and insert here some colors.

00:30.590 --> 00:31.160
White.

00:32.220 --> 00:32.760
Black.

00:34.330 --> 00:35.670
And read.

00:37.980 --> 00:42.900
Generally, we can change any of the values inside a right, for example, if we want to change the

00:42.900 --> 00:49.410
value of this second item, which is blek, we can simply access on the item and assign new value with

00:49.410 --> 00:54.600
equal operator right colors and indicate the index number one.

00:55.700 --> 00:57.710
And right here, the value as great.

00:59.590 --> 01:01.480
Let's look callers in council.

01:04.940 --> 01:08.420
And you see that black is removed and it's replaced with green.

01:09.550 --> 01:16.210
All right, let's talk about methods and demonstrate how some of them work, suppose that we want to

01:16.210 --> 01:17.740
add items to array.

01:18.310 --> 01:21.060
In this case, we can use method, which is called push.

01:21.400 --> 01:23.530
It's very frequently used in JavaScript.

01:23.950 --> 01:27.230
This method adds a new element at the end of an array.

01:27.700 --> 01:28.210
So right.

01:28.210 --> 01:29.530
Color start, push.

01:31.670 --> 01:35.390
And as an argument plays here, the color blue.

01:37.340 --> 01:45.050
Reload and you see that blue color is added at the end of the right and the length of the arrow has

01:45.050 --> 01:46.670
increased and became for.

01:48.130 --> 01:54.490
OK, as we said, push method as the element at the end of the era and in order to remove elements from

01:54.490 --> 01:59.920
the and we need to use another method, which is called pop the right colors, not pop.

02:01.500 --> 02:06.450
Because of that, methods are functions, we always need to use parentheses with them.

02:07.380 --> 02:10.350
Without and you see that blue has removed.

02:11.440 --> 02:19.200
So Push Method has added the item and pop method has removed it both happened at the end of the array.

02:19.900 --> 02:25.930
All right, if we need to remove or add the items at the beginning of the array, there are two methods

02:25.930 --> 02:29.350
for doing that, which are shift and on shift.

02:29.980 --> 02:32.320
Right colors that shift.

02:34.330 --> 02:38.690
That revolt and you see that first item is removed at the beginning of the year.

02:38.790 --> 02:44.050
Right now, let's add item for that use on Shifta method, right?

02:44.050 --> 02:45.520
Colors start on shift.

02:46.580 --> 02:55.640
And as an argument, let's sit here, the Color Purple rollout, and you see that we have purple at

02:55.640 --> 02:56.780
the beginning of the year, right?

02:58.100 --> 02:58.610
All right.

02:59.750 --> 03:05.390
The next and the last method that we are going to demonstrate is index of it's very useful.

03:05.390 --> 03:11.540
And also it's frequently used this method search the array for the specified item and the returns its

03:11.540 --> 03:12.050
position.

03:12.890 --> 03:21.200
So if we want to get the index number of red color in the array, we need to write colors DOT index

03:21.200 --> 03:21.500
of.

03:22.920 --> 03:26.030
And as an argument, that's right, you're right.

03:26.080 --> 03:26.340
Call.

03:28.550 --> 03:36.680
Reload and we got to, because the index number of red color is to let's search another color, which

03:36.680 --> 03:41.450
is not actually the array change read into, for example, brown.

03:43.500 --> 03:51.330
Then reload and you see that we have minus one, it means that the color brown wasn't found in the array

03:51.720 --> 03:54.420
and the index of the returned minus one.

03:55.320 --> 03:58.800
Generally, when we use index of method, an item is not found.

03:59.070 --> 04:01.020
It always returns minus one.

04:02.150 --> 04:10.280
All right, let's demonstrate our index of method is used with a little example, I'm going to use your

04:10.280 --> 04:14.190
if statements and check if the array includes blue color, right.

04:14.210 --> 04:16.790
The condition color, state index of.

04:18.610 --> 04:24.700
That insert here, blue color triple equals two, minus one.

04:27.070 --> 04:34.540
So if this condition is true, then it means that blue color doesn't exist in the area and then I'm

04:34.540 --> 04:43.540
going to add the Mashad color using push method, the right color start, push and insert here blue,

04:44.410 --> 04:46.420
then display colors in council.

04:46.930 --> 04:47.470
Right.

04:47.470 --> 04:49.720
Cancel that log colors.

04:50.820 --> 04:57.180
Revolt and you see that blue collar is added to the array because the condition in the if statement

04:57.180 --> 04:57.900
was true.

04:59.110 --> 05:03.310
This little example shows the usefulness of the index of method.

05:04.480 --> 05:06.880
OK, it was error methods.

05:07.240 --> 05:12.640
There are lots of useful and helpful methods regarding a race which you will meet throughout the course.

05:13.710 --> 05:15.080
All right, let's move on.
