DEV Community

Ayush
Ayush

Posted on • Updated on

Javascript Map Function Explained with Code

Learning outcomes of this tutorial
Map function explained

Map fucntion
Map function returns a new array based upon original array. Original array dosen't gets modified.

Map function can at most accept 3 parameters current Element, index, orignal Array of which index and orignal Array parameters are optional to add.

const orignalArray=[1,2,3,4,5]
const newArray = orignalArray.map((currentElement,currentIndex,orignalArray)=> 
     {return currentElement*2}
)
console.log("orignalArray: ",orignalArray)
console.log("new Array: ",newArray)
Enter fullscreen mode Exit fullscreen mode

Output
Image description

That's it for this blog.

Happy Learning !!
Happy Coding !!

Top comments (0)