Array.prototype.map() accepts a callback function as a parameter.
The callback function produces an element of the new Array and takes three arguments:
- currentValue - This is the current element being processed in the array.
- index (optional) - This is the index of the current element being processed in the array.
- array (optional) - The original array that map was called upon.
- thisArg (optional) - Value that you can use as this when executing the callback
const names = ['mike', 'john', 'anne']; const namesUppercase = names.map(name => name.toUpperCase()); console.log(namesUppercase); namesUppercase = ["MIKE", "JOHN", "ANNE"]
Top comments (0)