Last active
July 19, 2019 13:05
-
-
Save frankzickert/927b509534e48415c807683aca1e18ad to your computer and use it in GitHub Desktop.
map-example
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
/** input array */ | |
const arrInput = [1,4,2]; | |
/********* with Array.map ***************/ | |
const arrMap = arrInput.map(cur=>cur+2); | |
/********* with for-loop ****************/ | |
const arrOutput = new Array(); | |
for (var i in arrInput) { | |
arrOutput.push(arrInput[i]+2) | |
} | |
/** output */ | |
console.log("mapped: ", arrMap); | |
console.log("for-loop: ", arrOutput); | |
// console output: | |
// mapped: [3, 6, 4] | |
// for-loop: [3, 6, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment