The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
The map() method is the most commonly used function to iterate over an array of data in JSX. You can attach the map() method to the array and pass a callback function that gets called for each iteration. When rendering the User component, pass a unique value to the key prop
'Each child in a list should have a unique "key" prop' warning always appears.
keys() is a built-in JavaScript method that returns an array of the given object's property names in the same order as we get with a standard loop. The Object. keys() method takes an object as an argument and returns the array of strings representing all the enumerable properties of a given object.
The spread operator is a new addition to the set of operators in JavaScript ES6. It takes in an iterable (e.g an array) and expands it into individual elements. The spread operator is commonly used to make shallow copies of JS objects. Using this operator makes the code concise and enhances its readability.
- Copying an array.
- Concatenating or combining arrays.
- Using Math functions.
- Using an array as arguments.
- Adding an item to a list.
- Adding to state in React.
- Combining objects.
- Converting NodeList to an array.
let fruits = ["apples", "bananas"];
let vegetables = ["corn", "carrots"];
let produce = [...fruits, ...vegetables];
//["apples","bananas","corn","carrots"]