Hello and welcome him.
This video he'll be introducing you to JavaScript arrays.
What is an array an array is basically a structure that allows you to store multiple values in one single
reference.
Basically what that means is that it stores multiple values in a single variable.
So an array is a special variable which can hold more than one value at a time in comparison to a variable
that can only hold one value at a time.
An example of an array is this here for example you create an array called my data and you use it equals
two to assign the values.
You can tell it's an array because the values of an array are enclosed in square brackets.
Also you can have different data types in an array.
In this example here of course put number and string data type and values in an array so let's create
a simple array using our Web console to create an array.
You have to create the variable first.
So you just type in V A r to create or define a variable into a space followed by the name you want
to call a variable.
I'm going to call my my my data.
You then use it equals to sign to create the array.
I use the opening square brackets and you add the values or the elements in the array.
You can mix data types in my example here.
I'm going to mix the data type with a string and also a number sample a number and a shrink.
I'm going to add another number and then I'll add another string.
When you are using string.
Don't forget to enclose them in quotes.
And when you are using arrays you separate each of the elements in the array by a comma.
You can see a comma here and comma here.
Only the last value or element that does not require a comma.
So now that we've created an array to call the array we just need to call it by his name which is my
data.
And it would display the information the information here tells you that we've got an array of four
elements which is one two three four.
And it gives you the values.
If I expand this you will see all these figures here.
They're known as index.
The way you access the elements in an array is by the index.
So the very first element of value as index 0.
The next one will have index 1.
And so you can see here index 0 belongs to 7 index 1 belongs to John index to belong to 70 index 3 belongs
to Jane and so on tells you here the length of the array is 4 because it has four elements all values
inside the array.
So if I wanted to access JANE WALTON The way I would do that would be my data and then square brackets
and I'll type in three pick up best the index for Jane press enter and see it's giving me the value
of Jane because Jane has an index of three as you can see here from the index so always remember that
when you're trying to access the values in an array you have to access them using the index and index
starts from zero upwards when you work with arrays it is easy to remove elements and also add new elements
to an array using a process called poppin and pushing if you want to add element you use a method called
in to add an element and if you want to remove you use a method called popping so popping will remove
and pushing will add an element to an array so let's add an element to our Harry and the way we do that
we call the array by his name which is in my case is called my data.
And then you add a dot and type typing push and then in parent sees you specify the value you're trying
to push into the array let's say I'm trying to add a number 10 into the array and that press Enter so
you can see now is now showing that the array has five values.
So if I want to call this array a game called my data it will now show that the length is five you say
because I've now added a new element which is as number 10 here.
So if I expand that you can see the index.
We've got a new index for four which is number 10.
If I wanted to remove an element from array.
OK so I can do that using the pop method the pop method will remove the value that I've just add.
So let's remove the value I've just added for typing my data
dot pop and this will remove the very last value I've just added on.
Can see here tells me 10 has been removed so far.
Now references are now issued go back to the original value which is an array of four.
You can see here this is the original let's.
That's basically how you can add can move an element from an array.
So this concludes his brief introduction to JavaScript arrays.
There are other types of arrays and there are so many things you can do using javascript array.
This is just an introduction to what an array is.
Thank you for watching.
And by phone.