javascript / beginner
Snippet
Transforming Lists with Array.map()
The map() method creates a new array by applying a function to every element of the original array, which is perfect for generating lists of components in Next.js.
snippet.js
1
2
3
4
const numbers = [1, 2, 3];const doubled = numbers.map((num) => num * 2);console.log(doubled); // [2, 4, 6]
nextjs
Breakdown
1
numbers.map((num) => ...)
Iterates over each item in the numbers array.
2
num * 2
Multiplies the current number by two and adds it to the new array.