iterates over an array and performs specified actions on items in the array
If I want to loop through an array and display each value in JSX, how do I do that in React?
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li>{number}</li>
);
Each list item needs a unique __.
key
What is the purpose of a key?
a unique prop used when rendering lists in React
help react handle updating DOM effectively
The Spread Operator
What is the spread operator?
…
List 4 things that the spread operator can do.
Copying an array
Concatenating or combining arrays
Using Math functions
Using an array as arguments
Adding an item to a list
Adding to state in React
Combining objects
Converting NodeList to an array
Give an example of using the spread operator to combine two arrays.
let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
arr1 = […arr1, …arr2];
// arr1 is now [0, 1, 2, 3, 4, 5]
Give an example of using the spread operator to add a new item to an array.
let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
arr1 = […arr2, …arr1];
// arr1 is now [3, 4, 5, 0, 1, 2]
Give an example of using the spread operator to combine two objects into one.