Nodejs Array ForEach forEach(func)

Here you can find the source of forEach(func)

Method Source Code

/**/* w ww.j  a  v a  2  s  . co  m*/
 * forEach is a method of Array  to execute for each element of an Array
 *
 * @param func       a Function, accepte one argument, the array element
 * @return           Void;
 */
Array.prototype.forEach = function(func)
{
  for(var i = 0, l = this.length; i < l; i ++)
  {
    func(this[i]);
  }
};

Related

  1. forEach(fn, context)
    Array.prototype.forEach = function(fn, context) {
      if (typeof fn != "function") {
        throw new TypeError(fn + " is not a function");
      if (typeof context === 'undefined') {
        context = this;
      for (var i = 0, l = this.length; i < l; ++i) {
        fn.call(context, this[i], i, this);
    ...
    
  2. forEach(fun /*, thisp */)
    Array.prototype.forEach = Array.prototype.forEach || function(fun ) {
      "use strict";
      if (this === void 0 || this === null) throw new TypeError();
      var t = Object(this);
      var len = t.length >>> 0;
      if (typeof fun !== "function") throw new TypeError();
      var thisp = arguments[1];
      for (var i = 0; i < len; i++) {
        if (i in t) fun.call(thisp, t[i], i, t);
    ...
    
  3. forEach(fun /*, thisp*/)
    Array.prototype.forEach = function(fun )
        var len = this.length;
        if (typeof fun != "function")
          throw new TypeError();
        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
          if (i in this)
    ...
    
  4. forEach(fun /*, thisp*/)
    Array.prototype.forEach = Array.prototype.forEach || function(fun ) {
        var len = this.length >>> 0;
        if (typeof fun != "function") {
            throw new TypeError();
        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) {
                fun.call(thisp, this[i], i, this);
    ...
    
  5. forEach(fun, thisp)
    Array.prototype.forEach = function(fun, thisp) {
      "use strict";
      if (this === void 0 || this === null) {
        throw new TypeError();
      var t = Object(this);
      var len = t.length >>> 0;
      if (typeof fun !== "function") {
        throw new TypeError();
    ...
    
  6. forEach(func)
    Array.prototype.forEach = function (func) {
        var length = this.length;
        for (var i = 0; i < length; i++) {
            func(this[i]);
    
  7. forEach(func, thisObj)
    Array.prototype.forEach = Array.prototype.forEach || (Array.prototype.forEach = function(func, thisObj) {
      for (var i=0, l=this.length; i<l; ++i) {
        func.call(thisObj, this[i], i, this);
      };
    });
    
  8. forEach(iterator)
    Array.prototype.forEach = function(iterator) {
      for (var i = 0, len = this.length; i < len; i++) {
        iterator(this[i], i);
    };
    
  9. forEach(predicate)
    Array.prototype.forEach = function(predicate)
      for (var i = 0; i < this.length; i++)
        predicate(this[i]);
    Array.prototype.contains = function(o)
      return this.indexOf(o) >= 0;