The map functions transform their input by applying a function to each element and returning a vector the same length as the input. map (), map_if () and map_at () always return a list.
The map() function applies the specified function to every item of the passed iterable, yields the results, and returns an iterator.
Arrays are quite common when using React, typically as a variable stored in your state. Whether it’s an array of integers, strings, or even objects, you’ll likely need to iterate through it at some point in your JSX in order to display each value.. The way you do this is by using the JavaScript function map
.
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity , he best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys .
JavaScript, spread syntax refers to the use of an ellipsis of three dots (…) to expand an iterable object into the list of arguments. The spread operator was added to JavaScript in ES6 (ES2015), just like the rest parameters, which have the same syntax: three magic dots …
[…[“😋😛😜🤪😝”]] // Array [ “😋😛😜🤪😝” ] […“🙂🙃😉😊😇🥰😍🤩!”] // Array(9) [ “🙂”, “🙃”, “😉”, “😊”, “😇”, “🥰”, “😍”, “🤩”, “!” ]
const hello = {hello: “😋😛😜🤪😝”} const world = {world: “🙂🙃😉😊😇🥰😍🤩!”}
const helloWorld = {…hello,…world} console.log(helloWorld) // Object { hello: “😋😛😜🤪😝”, world: “🙂🙃😉😊😇🥰😍🤩!” }
const numbers = [37, -17, 7, 0] console.log(Math.min(numbers)) // NaN console.log(Math.min(…numbers)) // -17 console.log(Math.max(…numbers)) // 37
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() // 😂😂😂😂😂