Last active
November 14, 2019 13:51
-
-
Save iandesj/cc2d7e3ff9d45657501d86bc0f619f10 to your computer and use it in GitHub Desktop.
Examples of map() vs for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ]; | |
console.log('map() example'); | |
const upperCaseFruits = fruits.map((value) => { | |
return value.toUpperCase(); | |
}); | |
console.log('upperCaseFruits =', upperCaseFruits, '\n'); | |
console.log('for loop example'); | |
let upperCaseFruitsAgain = []; | |
for (let i = 0; i < fruits.length; i++) { | |
upperCaseFruitsAgain.push(fruits[i].toUpperCase()); | |
} | |
console.log('upperCaseFruitsAgain =', upperCaseFruitsAgain); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment