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


Parameter Meaning
value Current element
index Current position
array Full 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

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

You may also like...