Before we actually start to describe the main concepts of the version, I would like to introduce you
to some of the very popular and helpful built in JavaScript array methods which allow us to get the
wanted results using writing less code.
Generally, one of the main purposes of updating JavaScript from S5 to S6 was to minimize the amount
of code that you write.
That's why I'm going to describe our helper methods, by the way.
The main goal to use METION methods is to replace for loop whenever it's possible.
One of these methods you are already familiar with because we have used it several times previously.
I'm talking about a right for each method.
If you don't remember, it's well done.
Do not worry.
It happens usually.
And because of that we will recall how it actually works.
Besides the forge method, I'm going to describe map, filter, find every sub and reduce.
Each of these helpers will be discussed and compared to follow up, in order to see clearly the difference,
advantages and disadvantages between them.
All right, let's go to our code editor.
As we said, I'm going to remind you how far each method works for that.
I'm going to create an array names.
Let's insert here some names, Alex.
Then Mary, Niek and Jayne.
At first, in order to iterate through the items and get the names separately, let's use follow right
for then verbal I equals zero, then the condition is less than the length of names.
And then I plus plus let's run running council.
The name is.
And plus, your names, I.
Reload and of course, we have names, as we expected.
OK, we didn't get the same result using forage at first, let's make here a little border for better
readability.
And now let's use Fourche method rights names that forage.
As you remember, we need to pass your function, which will be actually an iterator function and forage
eRate item, this function will be executed as a parameter.
We need to pass your current item.
There is a special convention for our helpers and JavaScript.
I mean that, for example, when we use our name in plural form, that the current item, which is passed
as a parameter, is used in singular form.
So right name here and then gets result in council.
Right.
The name is.
And plus, the current item name.
Result.
And he said that we had the exact same result in council.
All right, before we actually compare Falu and Farish to each other, I'm going to show you how this
method works behind the scenes.
So here we have our array with its containing name items and also the function which is passed in for
each method and has the parameter name as a current item as it's in case.
Follow up, for example, has the iteration feature as well.
So it takes into account the number of items in array and executes this function for each of these items.
If you think about it, you will find that the name of this helper method for each device itself, the
feature it has.
OK, so code is run, function is executed for the first item, Alex, and we get in Castle, the name
is Alex.
And then it runs for second item, Mary.
And we have the name is Mary, and then the same happens for Nick and for Jane as well.
Then because of that, we do not have any more items in the forage terminates execution of this function.
Makes sense.
All right, so you see, we got the same results in both cases, but when we use force method, it's
kind of short way.
We type less and if you type less, it means that there is a lower chance to get errors in bugs.
The logic is much more simple than it is in case of volume because you do not need to define all of
those conditions.
This is an advantage because when you look at some codes, it's easier to understand what's going on.
So it's better to use forage instead of a loop in some cases.
But an advantage for for a loop is that it works faster than the other array hoppers.
All right.
Again, I recommend to test this method and also other methods that will be discussed on your own,
because those helpers or some kind of similar methods and it's easy to be confused if you do not practice
a lot.
OK, let's move on.