ES6 Array map()

πŸ” ES6 map() Method

The map() method creates a new array by applying a function to each item of an existing array.

βœ” Does not modify the original array
βœ” Returns a new array


🧠 Basic Syntax


ParameterMeaning
valueCurrent element
indexCurrent position
arrayFull array (optional)

πŸ” Example: Basic map()


 


🎯 Example: Using map() with Strings


 


🧩 map() in React (Very Important)

React commonly uses map() to render lists dynamically.

Example:


 

export default App;

βœ” Each element needs a unique key prop in React when rendering lists.


🏷️ Using map() with Objects


Rendering in React:



πŸ”§ map() + Arrow Function + JSX Example


 


πŸ“Œ Common Mistakes

❌ Missing key:


βœ” Correct way:



πŸŽ‰ Summary

FeatureValue
Creates new arrayβœ”
Useful in Reactβœ”
Does not modify original arrayβœ”
Common for rendering listsβœ”

You may also like...