javascript / beginner
Snippet
Transforming Data with Array.map()
The .map() method creates a new array by calling a function for every element in the original array. In Next.js, it is the standard way to render lists of items.
snippet.js
1
2
const frameworkList = ['Next.js', 'React', 'TypeScript'];const items = frameworkList.map((item) => <li key={item}>{item}</li>);
nextjs
Breakdown
1
frameworkList.map((item) => ...)
Iterates through each framework string to create a new JSX element.
2
key={item}
A unique identifier required by React to efficiently update lists.