Complete the code to render a list of names using map.
const names = ['Anna', 'Bob', 'Cara']; return ( <ul> {names.[1](name => <li key={name}>{name}</li>)} </ul> );
The map function transforms each item in the array into a React element to render.
Complete the code to add a unique key to each list item when mapping.
const items = ['apple', 'banana', 'cherry']; return ( <ul> {items.map(item => <li [1]={item}>{item}</li>)} </ul> );
React requires a key prop on list items to help identify elements uniquely.
Fix the error in the map callback parameter to correctly access the index.
const numbers = [1, 2, 3]; return ( <ul> {numbers.map((num, [1]) => <li key={num}>{num} - [1]</li>)} </ul> );
The second parameter in the map callback is conventionally named index to access the current item's position.
Fill both blanks to create a map that filters and transforms items.
const fruits = ['apple', 'banana', 'cherry', 'date']; const filtered = fruits .filter(fruit => fruit.length > [1]) .map(fruit => fruit.[2]());
We filter fruits with length greater than 5, then convert each to uppercase.
Fill all three blanks to create a dictionary from an array using map and reduce.
const data = ['a', 'bb', 'ccc']; const result = data.reduce((acc, [1]) => { acc[[2]] = [3]; return acc; }, {});
We use reduce to build an object where keys are the items and values are their lengths.