Skip to content

Instantly share code, notes, and snippets.

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