Why this topic matters as it relates to what I am studying in this module?
.map() returns a new array
By using .map()
Element
A key is a special string attribute included when creating lists of elments. They help REACT identify which items have changed, are added, or are removed.
A useful and quick syntax for adding itmes to arrays, combining objects or arrays, and spreading an array out into a functionβs arguments.
List 4 things that the spread operator can do.
Give an example of using the spread operator to combine two arrays.
[β¦[βππππ€ͺπβ]] // Array [ βππππ€ͺπβ ] [β¦βππππππ₯°ππ€©!β] // Array(9) [ βπβ, βπβ, βπβ, βπβ, βπβ, βπ₯°β, βπβ, βπ€©β, β!β ]
const hello = {hello: βππππ€ͺπβ} const world = {world: βππππππ₯°ππ€©!β}
const helloWorld = {β¦hello,β¦world} console.log(helloWorld) // Object { hello: βππππ€ͺπβ, world: βππππππ₯°ππ€©!β }
const fewFruit = [βπβ,βπβ,βπβ] const fewMoreFruit = [βπβ, βπβ, β¦fewFruit] console.log(fewMoreFruit) // Array(5) [ βπβ, βπβ, βπβ, βπβ, βπβ ]
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() // πππππ
Create the function wherever the state is that we are going to change
It takes in a person object. Loops throught the array to find a matching person object. Then using .map(), generates a new array with the updated count increment.
Just like you would any other prop, with dot notatation.
You could create a variable referencing the desired method, or you could simply use it in dot notation and pass it into the method being invoked.