The .map() Method
Mon Jul 18 2022 20:22:21 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
//.map takes an argument of a callback function and returns a new array
const animals = ['Hen', 'elephant', 'llama', 'leopard', 'ostrich', 'Whale', 'octopus', 'rabbit', 'lion', 'dog'];
// Create the secretMessage array below
const secretMessage = animals.map(animals =>{
return animals[0];
});
console.log(secretMessage.join(''));
//output 'HelloWorld'
const bigNumbers = [100, 200, 300, 400, 500];
// Create the smallNumbers array below
const smallNumbers = bigNumbers.map(bigNumbers =>{
return bigNumbers / 100;
});
console.log(smallNumbers)
//output [ 1, 2, 3, 4, 5 ]
content_copyCOPY
Comments