Nodejs Array Value first(attribut, value)

Here you can find the source of first(attribut, value)

Method Source Code

Array.prototype.first = function (attribut, value) {
    for (var i = 0; i < this.length; i++) {
        if (this[i][attribut] == value)
            return this.slice(i, i + 1)[0];
    }//  w w  w.java 2  s . co m

    return null;
};

Related

  1. allValuesSame()
    Array.prototype.allValuesSame = function() {
      for(var i = 1; i < this.length; i++)
        if(this[i] !== this[0])
          return false;
      return true;
    
  2. allValuesSame()
    var canvas = {};
    Array.prototype.allValuesSame = function() {
      for(var i = 1; i < this.length; i++) {
          if(this[i] !== this[0])
              return false;
      return true;
    
  3. byField(field, value)
    Array.prototype.byField = function(field, value) {
      return this.filter(function ( obj ) {
        return obj[field] == value;
      })[0]
    
  4. defaultIfEmpty(val)
    Array.prototype.defaultIfEmpty = function (val) {
      return this.length == 0 ? [val == null ? null : val] : this;
    };
    
  5. elementWithAttr(attr, value)
    Array.prototype.elementWithAttr = function (attr, value) {
        for(var i = 0; i < this.length; i += 1) {
            if(this[i][attr] === value) {
                return this[i];
        return null;
    };
    
  6. getNextValue(index)
    Array.prototype.getNextValue = function(index) {
      let nextIndex = index + 1;
      if(nextIndex < this.length) {
        return this[nextIndex];
      return null;
    
  7. hasWhere(property, value)
    Array.prototype.hasWhere = function (property, value) {
        "use strict";
        for(var i = 0; i < this.length; i++) {
            if(this[i][property] === value) {
                return true;
        return false;
    };
    ...
    
  8. iReduce(handler, initialValue)
    var ary = [0,1,2,3,4,5,6,7,8,9];
    var initialValue;
    Array.prototype.iReduce = function(handler, initialValue) {
      if (typeof handler !== 'function') {
        throw new Error(handler + 'is not a function!');
      var ary = this;
      var i = 0;
      var tempCurrent = initialValue;
    ...
    
  9. makeArray(value){
    Array.makeArray = function(value){
      if ( !value ) return [];
      if ( typeof value == "string" ) return [value];
      return Array.prototype.slice.call(value, 0);
    };