There's one last method that we're going to be covering in JavaScript, and that's the map method,
and it kind of ties everything together where we can reconstruct a brand new array using contents from
existing data so we can create a brand new array by calling a function and looping through each one
of the elements.
So, of course, there is a challenge for this lesson, and this is to use maps.
So this map is going to work similar to what we've seen earlier where we can reconstruct the array.
So we've got an array num array, all numbers in there.
And we're going to use that existing array and rebuild it.
Multiplying each one of the values by 50 and then returning it back into my party and I would lock out
the values of my operate into the console.
So go ahead and try this out.
You can pause the video and I'll walk you through it coming up.
So first thing that we need to do is construct our array.
So this is just going to be a no arrests are going to have a bunch of numbers in here.
Just come a separate them and they can just be any number we want.
Or we could use the existing array that we have within the sample.
So once we've created our array, save that and you can double check just to make sure you've got your
array there.
And we're going to build a brand new array.
So we're taking our map and we're going to use the number array.
So that existing array that we have and using the map method, we've got function for X at first of
all, console log out the value of X so you can see it within the console.
It's going to run the block a code.
So what it's doing is it's going through each one of the items in the array and holding the value of
that item as X. So we can do something with it.
And just as we saw before, whatever we're returning back is going to be part of the new map array.
So we're constructing this brand new map array and we're checking to see we're taking X and we're multiplying
it by 50.
So now when we get our brand new constructed array, all of the values we've used, all of the values
in the current number array, and we've simply multiplied them by 50.
So this is a really useful function as you've got a lot of data within an array.
And if you want to do something with that data, you can use a map in order to run blocks of code and
then reconstruct brand new arrays from that data.