Nodejs Array Each each(length, callback)

Here you can find the source of each(length, callback)

Method Source Code

Array.prototype.each = function(length, callback) {
  if (typeof length == 'function') {
    callback = length;// www.j  a v a2s  . c o  m
    length = this.length;
  }
  for (var i=0; i < length; i++) {
    callback(this[i]);
  }
};

Related

  1. each(func, scope)
    Array.prototype.each = function(func, scope) {
        for (var index = 0; index < this.length; index++) {
            func.call(scope || this, this[index]);
    };
    
  2. each(handler, context)
    Array.prototype.each = function (handler, context) {
        var size = this.length
        if (typeof context == "undefined") context = this
        for (var i = 0; i < size; i++) {
            if (handler.call(context, this[i], i) == false) break
    
  3. each(iterationFunction)
    Array.prototype.each = function(iterationFunction) {
        this.eachIndex(function(element, index) {
            iterationFunction(element);
        });
    };
    
  4. each(iterator)
    Array.prototype.each = function(iterator) {
      for(var i = 0; i < this.length; i++) {
        iterator(this[i], i);
    
  5. each(iterator, context)
    Array.prototype.each = function(iterator, context)
      for(var i = 0, length = this.length >>> 0; i < length; i++)
        if(i in this)
          if(iterator.call(context, this[i], i, this) === false)
            return;
    
  6. each(method)
    Array.prototype.each = function(method) {
      for (var i = 0; i < this.length; i++) {
        this[i][method]()
    
  7. each(method)
    Array.prototype.each = function(method) {
      var _handBreak = false;
      function _break() { _handBreak = true; }
      for (var i = this.length - 1; i >= 0; i--) {
        if (_handBreak) return this;
        method.call(this, this[i], i, _break); 
      return this;
    };
    ...
    
  8. each(method)
    Array.prototype.each = function(method) {
      var args = Array.prototype.slice.call(arguments,1)
      for (var i = 0; i < this.length; i++) {
        this[i][method].apply(this[i],args)
    
  9. each(visitor)
    Array.prototype.each = function(visitor) {
      var iterator = this.getIterator();
      while (iterator.hasNext()) {
        var ret = visitor.call(this, iterator.next(), iterator.current);
        if (ret === false)
          break;