Nodejs Array First Predicate first(predicate)

Here you can find the source of first(predicate)

Method Source Code

Array.prototype.first = function(predicate) {
    for (var i = 0, l = this.length; i < l; i++) {
        if (predicate(this[i]))
            return this[i];
    }/*ww  w  . j a  va  2  s .c om*/
}

Related

  1. first(func)
    Array.prototype.first = function (func) {
        var length = this.length,
            item = null;
        for (var i = 0; i < length; i++) {
            if (func(this[i])) {
                return this[i];
        return item;
    ...
    
  2. first(matching)
    Array.prototype.first = function(matching) {
        for (var i = 0; i < this.length; i++) {
      var entry = this[i];
      if (matching(entry) == true)
          return this[i];
        return null;
    
  3. first(n)
    Array.prototype.first = function (n) {
        'use strict';
        return this.slice(0, n || 1);
    };
    
  4. first(n)
    Array.prototype.first = function(n) {
      if (this.length === 0 || n < 0) return void 0;
      if (n === undefined) return this[0];
      if (n === 0) return [];
      return this.initial(this.length - n);
    };
    
  5. first(num)
    Array.prototype.first = function (num) {
       if (num !== undefined) {
          return this.slice(0, num);
       return this[0];
    };
    
  6. first(predicate)
    Array.prototype.first = function (predicate) {
        for (var i = 0; i < this.length; ++i) {
            if (predicate(this[i]))
                return this[i];
    };
    
  7. first(predicate, def)
    Array.prototype.first = function (predicate, def) {
      var l = this.length;
      if (!predicate) return l ? this[0] : def == null ? null : def;
      for (var i = 0; i < l; i++){
        if (predicate(this[i], i, this))
          return this[i];
      return def == null ? null : def;
    };
    ...