Instructor: So, I did the math,
and since the beginning of the course,
we have studied, exactly 23 different array methods.
And that's really amazing.
And not just because,
23 is my favorite number,
but because that means,
that you cannot do everything you can imagine, with arrays.
Now, the problem is that,
choosing between 23 different methods,
is not always easy.
And especially when you just started learning about them.
Right?
So probably, in your mind right now,
there is a big confusion,
between all these methods,
and about which one to use, when.
So, to help you out with that,
I created this summary lecture,
with all the 23 array methods.
And I believe, that the best way to figure out,
which method to use,
in each situation,
is by starting to ask the question,
what do I actually want from this method?
So do I want to mutate the original array,
or do I want a new array?
Do I maybe want an array index,
or do I want to retrieve an entire array element?
Or do I want to know,
if an array includes, a certain element,
or maybe I just want to get a new string,
to transform the array to a new value,
or simply to loop over the array?
Well, these are a lot of different scenarios,
and by asking exactly these questions,
we can now categorize the methods,
and then easily choose between them.
So this is kind of a framework, that I developed,
and so let me go briefly,
through all of these different scenarios with you.
So these are the methods that mutate the original array.
So if we want to add an element,
to the original array,
we can use push or unshift.
So we already talked about all of these methods,
so of course I will not explain them again,
this is just a reference for you to keep.
Now anyway, if we want to remove,
from the original,
then we use either,
pop, shift or splice.
And finally, we also talked about,
three other methods that mutate the original array,
which is the reverse, sort and fill methods.
Okay.
So keep in mind, that you have to be careful,
because they do change the underlying array,
that we're working with.
And that many times is not what we want.
So if instead, we want a new array,
then we can use one of these methods.
So if we want to calculate one array,
from the original, then we use map methods.
And this one we use all the time,
as it loops over the original array,
and creates a new one, based on that.
We can also create new arrays,
by filtering for a condition,
or by taking a slice of the original array.
We can also concatenate two arrays,
and create a new array based on that,
and finally, we can flatten the original array,
using flat and flatMap.
Next, sometimes we need an array index.
And for that,
we have the indexOf and findIndex methods.
Now the difference between them,
is that findIndex can basically search,
for an element in the array,
based on a test condition,
that we provide, in the callback function.
But besides that,
they are pretty similar,
and both give us the index,
of a certain element in an array.
Now, if we actually need the array element itself,
then we use, the find method.
And so this one again,
is based on a test condition,
specified in a callback function.
Next up, sometimes it's very important to know,
whether an array includes,
a certain element or not.
And for that we have,
includes, some and every.
So with includes,
we can simply test,
if an array contains a single value,
while on the other hand,
with some and every,
we can specify a condition,
based on a callback function.
So some is gonna return,
if at least one of the elements in the array,
satisfies the condition,
and every, only returns true,
if all of the elements,
satisfy the condition.
So these three methods,
are all return Boolean values,
which is very helpful,
in a condition.
For example, in an if/else statement.
Okay. So that's where you many times will use,
one of these methods.
Next up, sometimes we want to transform an array,
into a string.
And then we use the join method.
Or we might want to reduce the entire array,
to just one value.
And as we already know,
for that, we use the reduce method,
just as we studied in this section.
So in the reduce method, we use an accumulator,
which has like a snowball,
to boil down, an entire array,
to just one single value.
And that value can be of any type.
So it can be a number, string, Boolean,
or even an array or an object.
All right?
And so in fact, we could,
replace some of these methods that we have here,
with a reduce.
Now, if all we want to do,
is to just loop over an array,
without producing any new value,
we use the, forEach method.
So remember, this one does not create a new array,
and in fact, it doesn't create any new value.
All we do in the forEach method is to,
basically just do some work,
but not produce a new value.
All right? And that's it.
That's an overview of all the 23 methods,
that we can use on arrays.
And it might be a good idea,
to somehow keep this overview handy.
For example, print it out on a paper,
or just store it somewhere, on your computer.
Anyway, now all there's left to do in the section,
is to complete the final coding challenge.
So let's do that right in the next video.