Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Last active September 10, 2016 15:48

Revisions

  1. dengjonathan revised this gist Sep 10, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions forLoop.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // This script reimplements JavaScript's native Array.prototype.forEach

    var names = ['jon', 'jane', 'jack'];

    // something we want to do with each item in array
  2. dengjonathan revised this gist Sep 10, 2016. No changes.
  3. dengjonathan created this gist Sep 10, 2016.
    13 changes: 13 additions & 0 deletions forLoop.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // This script reimplements JavaScript's native Array.prototype.forEach

    var names = ['jon', 'jane', 'jack'];

    // something we want to do with each item in array
    var log = function(a) {
    console.log(a);
    }

    // using for loop
    for (var i = 0; i < names.length; i++) {
    log(names[i]);
    }