Let's continue talking about race, we have several functions and JavaScript, which we can use with
arrays, those functions are built in and they are called as array methods.
These methods make arrays more powerful and useful things in JavaScript before we actually demonstrate
them.
I would like to show you how we can change values dynamically in array.
Let's create variable colors and insert here some colors.
White.
Black.
And read.
Generally, we can change any of the values inside a right, for example, if we want to change the
value of this second item, which is blek, we can simply access on the item and assign new value with
equal operator right colors and indicate the index number one.
And right here, the value as great.
Let's look callers in council.
And you see that black is removed and it's replaced with green.
All right, let's talk about methods and demonstrate how some of them work, suppose that we want to
add items to array.
In this case, we can use method, which is called push.
It's very frequently used in JavaScript.
This method adds a new element at the end of an array.
So right.
Color start, push.
And as an argument plays here, the color blue.
Reload and you see that blue color is added at the end of the right and the length of the arrow has
increased and became for.
OK, as we said, push method as the element at the end of the era and in order to remove elements from
the and we need to use another method, which is called pop the right colors, not pop.
Because of that, methods are functions, we always need to use parentheses with them.
Without and you see that blue has removed.
So Push Method has added the item and pop method has removed it both happened at the end of the array.
All right, if we need to remove or add the items at the beginning of the array, there are two methods
for doing that, which are shift and on shift.
Right colors that shift.
That revolt and you see that first item is removed at the beginning of the year.
Right now, let's add item for that use on Shifta method, right?
Colors start on shift.
And as an argument, let's sit here, the Color Purple rollout, and you see that we have purple at
the beginning of the year, right?
All right.
The next and the last method that we are going to demonstrate is index of it's very useful.
And also it's frequently used this method search the array for the specified item and the returns its
position.
So if we want to get the index number of red color in the array, we need to write colors DOT index
of.
And as an argument, that's right, you're right.
Call.
Reload and we got to, because the index number of red color is to let's search another color, which
is not actually the array change read into, for example, brown.
Then reload and you see that we have minus one, it means that the color brown wasn't found in the array
and the index of the returned minus one.
Generally, when we use index of method, an item is not found.
It always returns minus one.
All right, let's demonstrate our index of method is used with a little example, I'm going to use your
if statements and check if the array includes blue color, right.
The condition color, state index of.
That insert here, blue color triple equals two, minus one.
So if this condition is true, then it means that blue color doesn't exist in the area and then I'm
going to add the Mashad color using push method, the right color start, push and insert here blue,
then display colors in council.
Right.
Cancel that log colors.
Revolt and you see that blue collar is added to the array because the condition in the if statement
was true.
This little example shows the usefulness of the index of method.
OK, it was error methods.
There are lots of useful and helpful methods regarding a race which you will meet throughout the course.
All right, let's move on.