Let's talk about another era helper method, which is map, as it was in case the forage method, I'm
going to compare map helper to follow.
Suppose that we have an array which consists of some numbers, so create variable numbers and insert
here numbers from, for example, one to five.
Then suppose that we want to multiply each of these numbers to ten, keep each iteration and result
in a new era without changing the original one.
So let's create an empty array and call it new array.
And then let's use for a loop to iterate through the numbers, right, for I equals to zero, then I
is less than the length of numbers array and then I plus plus.
So in order to add results in new array, I'm going to use known array method called push, which adds
new item into array as a last one.
So right now you are right that push.
And inside the parenthesis right numbers, I multiplied to 10, as we said, we want to create new array
and keep the original one at the same time.
So let's look both of them in cancel.
Right.
Cancel the log.
No.
And then consider that look, New Arite.
Reload.
And here we go, we have original array and the new era with new items.
All right.
It's one of the ways to reach this results, but we can do the same, but in a much simpler and easier
way.
Using Map Hopper, let's again make here some border.
I'm going to create a new variable and store the results into this variable, so let's call it map array.
Which equals to numbers and use here MUP Harper.
Syntax is very similar to forage method, we need to pursue an anonymous function.
And then let's pass as a parameter number in singular form, as it was previously.
All right, it's very important to remember that always when we deal with error happens, we need to
use a statement.
The right return, no.
Multiplied to 10.
Let's say in council, what we have looked at first, the original numbers are right
and then newly created variable, not a rate.
Revote.
And here we go, we have the exact same result as it was in case of Falbe, but in this case, you notice
very clearly that the amount of code is much less than in previous case.
We got the same result in much more simple way.
And the most important thing to note is that you realize at a glance that logic is much more simple
to understand.
Again, you must keep in mind always to use a written statement, because if we miss it.
Then the function will give us the values as undefined.
All right, let's take a look on how map Harper actually works behind the scenes.
Here we have our original array of numbers, then another array which is created using Map Harper and
the function itself.
So at first function is executed for first item one is multiplied to ten and the result is added to
an empty array.
Then function is executed for second item, which is two, it's multiplied to ten and the result is
added two new array as well.
And in the same way function is executed for the item, then for fourth item and for last item, which
is five.
And all the results are added to a new array again.
Remember that when we use Matara Helper, the original array is maintained as immutable, which means
that it's not changed.
Makes sense.
All right.
Let's writes one more example, suppose that we have an array of persons which consists of several objects
with properties, force them in last name, so create variable persons, then insert in its object with
properties.
First name John
and last name Smith.
Let's duplicate it twice and then change the values of properties, writes Bob.
Then Brown.
And the third one, Nick and Dought.
Now, suppose that we want to group first names in you arrange for that, the perfect way is to use
a right helper.
So let's create a variable, get first names.
Which equals to persons that Matt Puscifer, again, a function with parameter.
Person.
As we said, we are going to group first names of those objects, so we need to return the person that
first name.
So everything is ready, let's make again here little line.
And then, look, both variables in console, right, console the clock persons.
And then cancel the luck, get first names.
Reload.
And here we have our original persons array and then you array, which consists of first names of the
objects, you can try the same with follow and you will be ensured that map is much more convenient
and fast way to set up the same logic and get the same result.
All right, let's go ahead.