Skip to content

Instantly share code, notes, and snippets.

@frankzickert
Last active July 19, 2019 13:05
Show Gist options
  • Save frankzickert/927b509534e48415c807683aca1e18ad to your computer and use it in GitHub Desktop.
Save frankzickert/927b509534e48415c807683aca1e18ad to your computer and use it in GitHub Desktop.
map-example
/** 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