Nodejs Utililty Methods Array First Predicate

List of utility methods to do Array First Predicate

Description

The list of methods to do Array First Predicate are organized into topic(s).

Method

first(f)
Array.prototype.first = function(f){
    var i = 0;
    while(i < this.length){
        if(f == undefined){
            return this[i];
        if(f(this[i])){
           return this[i];
        i++;
    return null;
};
first(fn)
Array.prototype.first = function(fn) {
    if (Object.prototype.toString.call(this) !== '[object Array]') {
        throw new TypeError("`this` must be Array, not " + typeof this);
    if (typeof fn === 'undefined') {
        return this[0];
    if (typeof fn !== 'function') {
        throw new TypeError("Optional `argument[0]` must be predicate function if defined");
...
first(func)
Array.prototype.first = function(func) {
  return this.where(func)[0];
};
first(func)
Array.prototype.first = function(func) {
    var result = [];
    for(var i=0;i<this.length;i++) 
        if (func(this[i]))
            return this[i];
    return null;
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;
...
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;
first(n)
Array.prototype.first = function (n) {
    'use strict';
    return this.slice(0, n || 1);
};
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);
};
first(num)
Array.prototype.first = function (num) {
   if (num !== undefined) {
      return this.slice(0, num);
   return this[0];
};
first(predicate)
Array.prototype.first = function(predicate) {
    for (var i = 0, l = this.length; i < l; i++) {
        if (predicate(this[i]))
            return this[i];