Nodejs Array First Item first()

Here you can find the source of first()

Method Source Code

Array.prototype.first = function () {
    this.current = 0;/*w w w  .jav  a 2  s. c  o m*/
    // we don't want to touch the array
    return jQuery.extend(true, [], this[this.current]);
};
Array.prototype.last = function () {
    this.current = this.length - 1;
    // we don't want to touch the array
    return jQuery.extend(true, [], this[this.length - 1]);
};
Array.prototype.next = function () {
    this.current = this.current + 1;

    if (this.current === this.length) {
        this.current = 0;
    }

    // we don't want to touch the array
    return jQuery.extend(true, [], this[this.current]);
};
Array.prototype.prev = function () {
    this.current = this.current - 1;

    if (this.current < 0) {
        this.current = this.length - 1;
    }
    // we don't want to touch the array
    return jQuery.extend(true, [], this[this.current]);
};
Array.prototype.current = 0;

Related

  1. 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.")
    
  2. 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());
    
  3. first()
    Array.prototype.first = function () {
        return this[0];
    };
    
  4. first()
    var dict = { path: 24, montes:23, mike: 37, andrea: 21}
    var friends = []
    for (var name in dict) {
      friends.push(name + ":" + dict[name])
    console.log(friends)
    var dictAux = {}
    dictAux.alice = 34
    dictAux.bob = 4
    ...
    
  5. first()
    Array.prototype.first = function(){
        if (this.length > 0)
            return this[0];
        else
            return [];
    
  6. first()
    Array.prototype.first = function () {
        return this[0];
    };
    
  7. first()
    Array.prototype.first = function() {
      return this[0];
    Array.prototype.last = function() {
      return this[this.length-1];
    
  8. first()
    Array.prototype.first = function() {
      return this[0];
    
  9. first()
    Array.prototype.first = function() {
        if (this.isEmpty()) {
            return null;
        return this[0];
    };