.map en js code example
Example 1: javascript map array
const myArray = ['Sam', 'Alice', 'Nick', 'Matt'];
const newArray = myArray.map(name => {
return 'My name is ' + name;
});
console.log(newArray);
const anotherArray = myArray.map((value, index) => index + ": " + value);
console.log(anotherArray);
console.log(myArray);
Example 2: javascript map
const numbers = [0,1,2,3];
console.log(numbers.map((number) => {
return number;
}));
Example 3: map function javascript
var rebels = pilots.filter(function (pilot) { return pilot.faction === "Rebels";});var empire = pilots.filter(function (pilot) { return pilot.faction === "Empire";});
Example 4: js map function
const exampleArray = ['aa','bbc','ccdd'];
console.log(exampleArray.map(a => a.length));