Understanding JavaScript’s map()

0
656
views
Understanding JavaScript's map()

JavaScript’s map function is extremely useful, but it can also be a bit confusing when you’re just starting out with programming.

So here’s a breakdown of what it does exactly, and how to use it.

And by the way, if you need to catch up on JavaScript itself, I suggest you check out our JavaScript Primer first.

map() vs Map()

Note that this article is about the Array.map() method, not the new Map object.

The Definition

First, let’s start with the Mozilla Developer Network’s own definition:

The map() method creates a new array with the results of calling a provided function on every element in this array.

There’s a lot to unpack here! Before we start trying to understand this sentence, let’s try and isolate the different characters in this little story:

The map() method creates a new array with the results of calling a provided function on every element in this array.

As you can see, we have five different types of objects:

  • An array
  • The elements contained within this array
  • A function
  • The results returned by this function
  • new array

Read Full Article

LEAVE A REPLY

Please enter your comment!
Please enter your name here