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:
β 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 | β |
