Nodejs Array Each each(callback)

Here you can find the source of each(callback)

Method Source Code

Array.prototype.each = function(callback) {
    for (var i = 0 ; i < this.length ; i++ )
        callback(this[i]);//from   w  w w  . j  a v  a  2  s  .  c o  m
}

Array.prototype.lastElement = function() {
    return (this.length === 0) ? undefined : this[this.length - 1];
}

Array.prototype.verify = function(callback){ 
    var newArray = [];
    for (var i = 0 ; i < this.length; i++) if(callback(this[i])) newArray.push(this[i]); 
    return newArray;
}

Array.prototype.unique = function() {
    var a = this.concat();
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
        }
    }

    return a;
};

Array.prototype.isEmpty = function() {
    return (this.length === 0);   
}

Array.prototype.hasSubArray = function(subArray) {
    for (var i = 0; i < subArray.length; i++)
        if (this.indexOf(subArray[i]) === -1)
            return false;
    return true;
}

Related

  1. each(callback)
    Array.prototype.each = function(callback){
      var count = 0;
      for (var i = 0; i < this.length; i++){
        var el = this[i];
        callback.call(this,el,count);
        count++;
    
  2. each(callback)
    Array.prototype.each = function(callback) {
      for (var i = 0;i < this.length;i++) {
        callback(this[i], i);
    };
    
  3. each(callback)
    Array.prototype.each = function(callback) {
      for(var i = 0, l = this.length; i < l; i++) {
        callback(i, this[i]);
      return this;
    
  4. each(callback)
    Array.prototype.each = Array.prototype.each || function (callback) {
        var self = this;
        for (var i = 0; i < self.length; i++) {
            var item = self[i];
            callback(i, item);
    
  5. each(callback)
    Array.prototype.each = function (callback) {
      for (var i = 0; i < this.length; i++) {
        callback(this[i]);
      return this;
    };
    
  6. each(callback)
    Array.prototype.each = function(callback) {
      for ( var i = 0; i < this.length; i++ ){
        if (callback(this[i], i, this) !== undefined) return;
    };
    Array.prototype.each = function(callback) {
      return this.some(callback);
    };
    
  7. each(callback)
    Array.prototype.each = function (callback) {
      for(var i=0; i<this.length; i++){
        if ( callback(this[i]) == false ){
          break;
      return this;
    };
    
  8. each(cb)
    Array.prototype.each = function(cb) {
      for (var i = 0; i < this.length; i++) {
        cb(this[i])
    
  9. each(cb)
    Array.prototype.each = function(cb) {
        for (var i = 0; i < this.length; i += 1) {
            cb(this[i], i)
    };
    function stringify(arr) {
        var ret = [];
        arr.each(function(el) {
            console.log(el);
    ...