It's time to talk about next very important aspect, I'm going to discuss what a race are in JavaScript.
eRate is a special type of a variable.
It doesn't store just one value.
It stores a list of values.
Eraser especially helpful when you do not know how many items at least will contain, because when you
create the array, you do not need to specify how many values it will hold.
All right, you create an array and give it a name, just like you would do for any other variable using
the word keyword, followed by the name of the array.
The values are assigned to the array inside a pair of square brackets, and each value is separated
by a comma.
Let's write names, for example, John.
Then Bob and Mary.
In this case, we have an array which consists of three values, but you can pass either strings or
numbers or any data type you would like, you're able to create array with different data types simultaneously,
like strings, numbers, boolean values.
Even erase.
And so on, this technique of creating Erra is known as a right literal, it's usually the preferred
method for creating a race.
As you noticed, we can use a right to store multiple values inside one variable.
This is very convenient and helpful because it allows us to avoid creating multiple variables at the
same time.
Let's log it in council.
Right.
Cancel that lock array.
So here we have our right values in an array are accessed as if they are in a number, at least it's
important to note that the numbering of this list starts at zero and not one.
Each item in an array is automatically given a number, and it's called an index.
This can be used to access specific items in the array, so you see that the first item, John, has
an index number zero, the second item has index one and etc. They said we have for the sixth member,
which is itself an array, and it consists of three values and they are numbered in the same way as
well.
You can also see here a length, which is a property of an array, and it shows us the number of items
array includes.
As you see, the main array consists of six items and the second array consists of three values that
is very useful property, and it's frequently used when we deal with arrays below the property.
You can see underscore, underscore, Proteau, underscore, underscore, but you can just ignore it
because we will talk about it in coming sections.
All right.
In order to access on the specific item of all right, we can do it using index.
So if you need to access, for example, on the first item, John, you need to write the name of the
array and in the square brackets, the index number of the item.
As you remember, a number of the items always starts with zero, so John has the index number at zero.
Let's reload.
And you see we have John in the same way you can access all the other items.
Let's change zero to one and see.
We've got the second item in order to get access on items of array, which is placed inside the main
array.
At first we need to have access on the main array itself.
So.
Right.
Index number five.
So we have accessed on it, right, but in order to access all the item of it, we need to write the
following open and other square brackets and write the index of specific item without.
And you see to which is the second item of the second array.
All right.
As we said, we can pass into any kind of data type and even the functions.
Let's see how to do it.
But before that, let's organize our code, make some white spaces here.
You may remember that JavaScript allows us to use multiple white spaces for better readability.
Then right function.
In this case, we don't need to assign a name to the function because we can call it using variable
name and proper index number, as you remember, this kind of functions are called anonymous functions
because they don't have names.
Let's pass here the parameter name and then inside curly braces, right, return hello, plus name.
At first, let's access on the function itself, right?
Index number six, reload, and we have our function here in order to invoke it.
We just need to add parentheses after the square brackets.
And also as the argument, let's pass the first item of the array, which is John, and which has the
index number zero.
Without and the function is called and the code is executed.
We have here.
Hello, John.
All right.
We can create a race using another method, which is called a right constructor, for that, we need
keyword new, which is an operator.
It's followed by the word array.
Starting with Capital Letter.
And inside the parentheses, we can pass a list of values.
Let's look right in council.
And you see that we have here our newly created a right.
All right, using first method, which was literal notation, is much better than a constructor because
of less typing and also for simplicity, readability and execution speed.
So I recommend all ways to use it.
OK, in this lecture, we have considered what our rights are, how to create them with literal notation
and eRate constructor.
As for the array methods, see you in the next video.