Welcome back to Learn to Code and JavaScript and this lecture, when I start looking at a raise for
next four lectures, I'm going to look at arrays, including this one.
The first two are going to be pretty basic.
The next two are going to be a little bit more advanced.
So it's possible you may want to skip the second two until later.
So anyway, let's get into arrays.
What always give us they're a collection of values and the values do not have to be the same type in
JavaScript.
So think of what we know so far, which is variables.
So it's kind of boring to say that I have a name.
I can't do much with it.
What I might want to do is have 100 names and do something with all 100 of them.
So this is what arrays allow you to do.
So you have a very literals Nerdfighteria square brackets with the values separated by commas so it
could look like this Mirae equals square bracket one comma three.
Come a five, come on seven, come in line in the square brackets, semicolon.
Or it could look like this.
You don't have to be the same types.
Another day equals five comma.
Hello cometrue.
So this area has three different types.
Array elements are then accessed by zero based index.
So in our example with my array, my array index one or people say sub one, the value is three because
the zero value is number one.
The number one value is number three.
And this is a lot like strings of recall string characters are zero based.
You can update a value in an array so I can say my array index or my razib two equals fifty five.
So this replaces the five with 55 and then an array length property like string length can give you
the number of elements in the array.
So the actual array length can't be changed once it's initialized.
But there are certain methods that return an array with a different length.
So we'll take a look at those.
So let's look at some examples of initializing a raise and making use of the values in an array.
So here's our starting application, so let's do a few things with the race so array variables are defined
like other variables you use left or const.
So I can say let my array equals to come before a comma six, comma eight.
And now this array will have five elements with those values.
So if I just cancel, log out an array
and the length.
Here's what we get.
So I can see that already tells me the length in parentheses, so the council tells me that and if I
open up a little a little triangle, it will expand the element.
So if there is a thousand elements that will show them to me on the first one.
And then my life is out here and you see the life is built into the ray.
So it's listed in there as well.
So let's make a change.
Two equals five thousand.
And we will just copy this.
And run it, so now our number five has been replaced by 5000 in the array.
I can reassign a new array to the array so I can say my array equals Hello World.
Twenty three.
And then when we come to work that out, we'll have the Nuray, so keep in mind, this is a totally
distinct array.
Then the array that we created up here only has three elements.
It's got two strings, one number.
A world 23.
All right, so that's an introduction to initializing an array and manipulating it.
So next, we're going to look at some selected array methods.