Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iandesj
Last active November 14, 2019 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandesj/cc2d7e3ff9d45657501d86bc0f619f10 to your computer and use it in GitHub Desktop.
Save iandesj/cc2d7e3ff9d45657501d86bc0f619f10 to your computer and use it in GitHub Desktop.
Examples of map() vs for loop
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