Reading-Notes

Class 03: React and Forms


What does .map() return?

  - map returns a new array.


- ## 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() // πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚

```