Nodejs Array Last last(value)

Here you can find the source of last(value)

Method Source Code

// *****************************************************************************
// Arrays/*w w w  .  ja va2 s  . c  om*/

Array.prototype.last = function(value) {
   
   if (this.length) {
      
      var last = this[this.length-1];
      
      if (value != undefined)
         return (value == last) ? true : false;
      else   
         return last;
   }
   
   return '';

};

Related

  1. last(n)
    Array.prototype.last = function (n) {
        'use strict';
        return this.slice(this.length - (n || 1), this.length);
    };
    
  2. last(n)
    Array.prototype.last = function(n) {
      if (this.length == 0 || n < 0) return void 0;
      if (n == undefined) return this[this.length - 1];
      if (n == 0) return [];
      return this.rest(this.length - n);
    };
    
  3. last(num)
    Array.prototype.last = function (num) {
       if (num !== undefined) {
          return this.slice(-num);
       return this[this.length - 1];
    };
    
  4. last(predicate, def)
    Array.prototype.last = function (predicate, def) {
      var l = this.length;
      if (!predicate) return l ? this[l - 1] : def == null ? null : def;
      while (l-- > 0){
        if (predicate(this[l], l, this))
          return this[l];
      return def == null ? null : def;
    };
    ...
    
  5. last(t)
    Array.prototype.last = function(t) {
      if (t !== undefined) {
        this[this.length - 1] = t;
      } else {
        return this[this.length - 1];
    
  6. last(value)
    Array.prototype.last = function(value) {
      if (this.length) {
        var last = this[this.length-1];
        if (value != undefined)
          return (value == last) ? true : false;
        else  
          return last;
      return '';
    ...
    
  7. last100()
    Array.prototype.last100 = function () {
        if (this.length < 100) return this;
        var last100 = [];
        var start = this.length-101;
        for (var i = 0; i < 100; i++)
          last100.push(this[i + start]);
        return last100;