map()
function. We return a <li>
element for each item. Finally, we assign the resulting array of elements to listItems
,We include the entire listItems
array inside a <ul>
element, and render it to the DOM
codeExample1. What is the spread operator?
JavaScript, spread syntax refers to the use of an ellipsis of three dots (β¦)
to expand an iterable object into the list of arguments.
2.List 4 things that the spread operator can do.
3.Give an example of using the spread operator to combine two arrays. the spread operator can quickly combine two arrays, an operation known as array concatenation
const myArray = [`π€ͺ`,`π»`,`π`]
const yourArray = [`π`,`π€`,`π€©`]
const ourArray = [...myArray,...yourArray]
console.log(...ourArray) // π€ͺ π» π π π€ π€©
4. 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) [ "π", "π", "π", "π", "π" ]
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() // πππππ
increment
map()