Before we get into our project, let me explain to you what is an array.
An array is basically the way you can store more than one information, more than one data or different
types of data into one single variable.
Because right now what we have is if I have a name and I want to store that name into a variable, I
just do like this.
That's it.
My name is Andre is store to a variable name.
But what happens if I have more than one name?
So for example, and how can I store both data and representing the data is as a single, as a single
or as a two pieces of data in one single variable.
The way I can do that is using arrays.
So I'm going to start the same way.
Let me just it makes a little bit bigger.
I'm going to start the same way.
Let and I will give the array name as a variable.
I will call my one friends.
Friends.
There we go.
So I'm going to build a list of friends.
And to build this list, I need to use the square brackets.
So I open and close the square brackets and inside I should give the data or the list of friends that
I have right now.
Yeah.
So let me just make some names up over here.
Alum and then we have Mark and then I should put in a single code and then comma is space single calls
again.
The third one, let's say Julia and the fourth and last I would say Bella.
There we go.
Cool.
So this is an array.
Just take the zoom out.
This is an array.
This array has four items inside just to make our lives simple.
Those four items are strings.
I didn't put any integer over here.
How can I return the full array?
The full list of items to the console?
Same way I do with the normal variable console dot log and then the name of my variable.
In this case the name of my array save.
And here I have.
So I have the alum Mark, Julia and Bella.
The length.
It's four and the prototype.
It is an array and it's coming from main line number three over here at the right hand corner.
Great.
What else can I learn about arrays?
Each position inside of an array can be represented, or it is represented by a number.
And this number recall index.
So let's say for any reason I need to call a single item inside of an array.
How can I do that?
I go for the console dot log.
My array name is France and inside of my square brackets I can type a number.
And this number is the index number representing the location of each item inside of the array.
So if I put a number one in here, what do you think is going to come up?
So let me just.
Do this.
What do you think is going to come up as a result?
Let's check it out.
Save and comes up, Mark.
You may be thinking, why is Mark if we check this out, the index number starts counting as a zero.
So alum is the index position.
Zero.
Mark is number one, Julia is number two and Baylor is number three.
A lot of people get very confused with this because they think number one is the first one in here.
But indexes, they start counting as zero.
That's why we have that.
And if you did really pay attention, which I believe you did, you saw the numbers.
When I expanded this arrow over here, I believe you saw the numbers and the numbers pre prior or before
the name or before the item.
They are the indexes.
So let me just take my pan off here and this is what I'm talking about.
There we go.
Index zero.
Index one.
Index two.
And the index three.
This length is four.
So with that said, can I replace items inside of my array?
Let's see.
Let's see if I can replace some items over here.
I want to replace the item number one mark.
So I'm going to say France.
I'm going to call my array again.
And for for the French in the position index, number one, this position will have a new value.
And this now new value is going to be an.
So as soon as I save my project, Mark should go away.
It will be replaced by an and over here as well saving.
And here we are replace it the position index number one.
What happened if I if I type an item name or given a data to an item and with an index that doesn't
exist.
So let's say index number what we have we have 10123 index number four.
What do you think is going to happen.
So France index number four equals to.
Joe.
Yeah.
Joey.
Save the config.
And look what happened.
Index number four didn't exist, but because the array is dynamic and you can increase and decrease
its size, it size dynamically.
The friend's index number four didn't exist, but now it does is just add to the end.
I can do that for index number five, six and seven and so on.
So if the number of the index does have some data, it will be replaced.
Otherwise it will be just added to the list.
So cool one.
And don't forget that inside of the array list, you can also add different types of data.
Right now we did the we did the string, but we can also add the integer or a number.
So let's say friends and the index number five and the inside of the index.
Number five will have the value 100 save.
And now we have the value 101 hundred belongs to the index number five.
Arrays.
It's a great way to restore more than one type of data or one data into an variable.
Very useful.