.map() returns a new array
Inside a the render() method of a react component, loop though the array (using the .map() function or another looping mechanism) and return new JSX elements for each item.
key
Keys help React identify which items have changed, are added, or are removed.
The spread operator looks identical to the rest operator (…), and it lets you expand iterables (like arrays and strings) into their individual elements.
Copy an array
Concatenate arrays
Copying and merging objects
Conditionally adding items to an object
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
arr1 = […arr1, …arr2]
arr1 is now [1, 2, 3, 4, 5, 6]
let isSummer = false;
const fruits = [“apple”, “banana”, …(isSummer ? “watermelon” : [])];
This will add the string “watermelon” to the array isSummer only if isSummer evaluates to true. Otherwise it will spread an empty array, so nothing is added.
const obj1 = {foo: “bar”, x: 42}; const obj2 = {bar: “baz”, y: 13};
const mergedObj = {…obj1, …obj2};
This will make the new mergedObj equal to {foo: “bar”, x: 42, bar: “baz”, y:13}
Keys in React - is using the index as a key sufficient?