Nodejs Array First Item first()

Here you can find the source of first()

Method Source Code

// A JavaScript object is a table mapping string property names to values.
// This makes objects pleasantly lightweight for implemeting dictionaries:
// variable-sized collections mapping strings to values.

var dict = { path: 24, montes:23, mike: 37, andrea: 21}
var friends = []/*from   w w  w .ja va2  s . c om*/


for (var name in dict) {
  friends.push(name + ":" + dict[name])
}

console.log(friends)

// Deceptively, since we can add propertie to any type of JavaScript object 
// this usage pattern will sometimes appear to work:

var dictAux = {}

dictAux.alice = 34
dictAux.bob = 4
dictAu.chirs = 3

Array.prototype.first = function () {
  return this[0]
}

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

var names = []

for (var name in dictAux) {
  names.push(name)
}

console.log(names)

Related

  1. first()
    Array.prototype.first = function() {
      return this[0];
    Array.prototype.last = function() {
      return this.reverse()[0];
    
  2. first()
    Array.prototype.first = function(){
        if(this.length > 0)
            return this[0];
        return null;
    };
    
  3. 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.")
    
  4. 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());
    
  5. first()
    Array.prototype.first = function () {
        return this[0];
    };
    
  6. first()
    Array.prototype.first = function(){
        if (this.length > 0)
            return this[0];
        else
            return [];
    
  7. first()
    Array.prototype.first = function () {
        this.current = 0;
        return jQuery.extend(true, [], this[this.current]);
    };
    Array.prototype.last = function () {
        this.current = this.length - 1;
        return jQuery.extend(true, [], this[this.length - 1]);
    };
    Array.prototype.next = function () {
    ...
    
  8. first()
    Array.prototype.first = function () {
        return this[0];
    };
    
  9. first()
    Array.prototype.first = function() {
      return this[0];
    Array.prototype.last = function() {
      return this[this.length-1];