The functional programming function map in a Javascript context is only an array method as all functional programming javascript method.
For the map data type, see Javascript - Map Data Type
With an Arrow function as argument
const letters = ['A', 'B', 'C', 'D', 'E'];
console.log("Showing only the function value call");
const lowercases = letters.map((letter) => letter.toLowerCase());
console.log(lowercases);
console.log("Showing the value, index call");
letters.map((letter, index) => console.log("Letter at position "+index+" is "+letter.toLowerCase()));
With an Javascript - Function Declaration
function double(num) {
return 2*num;
}
const numbers = [1, 2, 3, 4, 5];
// Passing the function name
const doubled = numbers.map(double);
// Declaring the function inside the map works also
const doubled2 = numbers.map(function double(num) {
return 2*num;
});
console.log("doubled data");
console.log(doubled);
console.log("doubled2 data");
console.log(doubled2);
myArray.map((element, index) => { ... });
map((element, index, myArray) => { ... });
map builds a new array that you should use otherwise use other loop construction such as foreach or for…of