Skip to content

Instantly share code, notes, and snippets.

@javanigus
Created January 11, 2018 21:31
Show Gist options
  • Save javanigus/fadcc5e50ef7c3ca45f299135712cd43 to your computer and use it in GitHub Desktop.
Save javanigus/fadcc5e50ef7c3ca45f299135712cd43 to your computer and use it in GitHub Desktop.
Example JavaScript Map Function
// INPUT
let numbers = [1, 2, 3, 4];
let results = [];
// MULTIPLY EACH ARRAY ITEM BY 2
function multiplyBy2(currentValue, index, arr) {
return currentValue*2;
}
results = numbers.map(multiplyBy2);
// OUTPUT
// [2, 4, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment