Nodejs Array First Item first()

Here you can find the source of first()

Method Source Code

Array.prototype.first=function(){
return this[0]//from   www  . j a  va2  s.  c  om
}

Array.prototype.last=function(){
return this[this.length-1]
}

Related

  1. first()
    Array.prototype.first = function() {
      return this[0];
    };
    
  2. first()
    Array.prototype.first = function() {
      return this[0];
    Array.prototype.last = function() {
      return this.reverse()[0];
    
  3. first()
    Array.prototype.first = function(){
        if(this.length > 0)
            return this[0];
        return null;
    };
    
  4. first()
    Array.prototype.first = function() {
      if (this[0] !== undefined)
        return this[0]
      else {
        throw new TypeError("Can't get first element of an empty array.")
    
  5. first()
    "use strict";
    Array.prototype.first = function  () {
      if (this.length === 0) {
        throw "Empty string doesn't have first element";
      return this[0];
    };
    console.log(["a", "b", 3].first());