- map returns a new array.
- Using curly braces. ``` You can build collections of elements and include them in JSX using curly braces {}.
- ## Each list item needs a unique ____.
- key
- ## What is the purpose of a key?
- to specifically identify which items have changed or added or removed.
<hr>
# The Spread Operator
- ## What is the spread operator?
- spreads array's into seperate arugments
- ## List 4 things that the spread operator can do.
- copy an array
- add to state in react
- converting nodelist to an array
- combining objects
- ## Give an example of using the spread operator to combine two arrays.
const myArray = [π€ͺ
,π»
,π
]
const yourArray = [π
,π€
,π€©
]
const ourArray = [β¦myArray,β¦yourArray]
console.log(β¦ourArray) // π€ͺ π» π π π€ π€©
- ## Give an example of using the spread operator to add a new item to an array.
const fewFruit = [βπβ,βπβ,βπβ] const fewMoreFruit = [βπβ, βπβ, β¦fewFruit] console.log(fewMoreFruit) // Array(5) [ βπβ, βπβ, βπβ, βπβ, βπβ ]
- ## Give an example of using the spread operator to combine two objects into one.
const objectOne = {hello: βπ€ͺβ} const objectTwo = {world: βπ»β} const objectThree = {β¦objectOne, β¦objectTwo, laugh: βπβ} console.log(objectThree) // Object { hello: βπ€ͺβ, world: βπ»β, laugh: βπβ } const objectFour = {β¦objectOne, β¦objectTwo, laugh: () => {console.log(βπβ.repeat(5))}} objectFour.laugh() // πππππ
```