DEV Community

Shubham Jadhav
Shubham Jadhav

Posted on

Array.map() Method in JavaScript πŸš€

Hello, guys today we are covering one of the most important topic.
Today we are learning map() method, so let's start today's article.

πŸ‘‰ Article Content
β€’ What is Array.map() method ?
β€’ Syntax of Array.map() method ?
β€’ Use of Array.map() method ?
β€’ Example of Array.map() method ?
β€’ Explanation of example

πŸ‘‰ What is Array.map() method ?
=> The map() method is used for array transformation. It takes another custom function as an argument and on each array item applies that function.

πŸ‘‰ Syntax of Array.map() method ?
=> syntax

πŸ‘‰ Use of Array.map() method ?
=> Map() method used to iterate over an all array item one by one and apply function on each array items.

πŸ‘‰ Example of Array.map() method
=> See following image
Example

πŸ‘‰ Explanation
=> As shown above image we need an array with some values. That's why I am created an array and it's name is 'arr' and stored [1,2,3,4,5] this values.

Now I am using map() method to increase every array item by one.

I used map() method and pass a function and this function takes one argument and this argument hold all the array items.

When this method call all array items iterate one by one and apply function. When array item '1' is pass through a map() method it's simply increment by 1.

πŸ‘‰ Map() method take a function which will be arrows function or normal Js function.

πŸ‘‰ This method works like a loop and it's similar to for and forEach.

πŸ™ Thank you for reading....

Top comments (4)

Collapse
 
strubloid profile image
Strubloid

Yeah... Why you guys only show newbie things? How about show a real use of it? When you want to iterate through values, change specific ones and return a new array with something in it? Maybe a decorator can be explained inside of it....

Collapse
 
grig13 profile image
Mazureanu Grigorian

Well... I think because the author of every article can make the article's content to be of whatever level he wants? Like if he wants to be a newbie tutorial he can do that. You can take what he showed here to the next level. I'm sure there are more complex things

Collapse
 
lgrammel profile image
Lars Grammel

Personally I would use .forEach in the example above, because the values that are being returned from .map are not used.

Collapse
 
kenstarry profile image
Kenneth Michuki

Excellent!!