Nodejs Array Find find_by(prop, val)

Here you can find the source of find_by(prop, val)

Method Source Code

// Find an object in an array of objects using
// a property-value
// Prerequisite: Array.prototype.first

Array.prototype.find_by = function(prop, val) {
  return this.filter(function(obj) {
    return obj[prop] === val
  }).first()/*www. ja  v  a 2s .  c o m*/
}

Related

  1. findInJson(attr, value)
    Array.prototype.findInJson = function (attr, value){
      for(var i=0; i<this.length; i++){
        this[i][attr] = this[i][attr].toLowerCase();
        if(this[i][attr] == value){
          return true;
        };
      };
      return false;
    };
    ...
    
  2. findMaximumfindIt()
    var array = [47, 98, 0, -23, 4, 87.3, 0.0003, +9];
    Array.prototype.findMaximum = function findIt() {
    var arrayValue = 0;
    for(var i = 0; i < array.length; i++) {
      if (array[i] > arrayValue) {
        arrayValue = array[i];
      return arrayValue;
    ...
    
  3. findRanges()
    Array.prototype.findRanges = function() {
      var buckets = {};
      for(var i = 0; i < this.length; i++) {
        if(!(this[i] in buckets)) {
          buckets[this[i]] = [{
            from: i,
            to: i
          }]
        } else {
    ...
    
  4. findThing(n)
    Array.prototype.findThing = function(n){
      for(var i=0; i<this.length; i++){
        if(this[i] === n){
          return true;
        };
      };
      return false;
    };
    
  5. findYoungestPersonfindYoungestPerson()
    Array.prototype.findYoungestPerson = function findYoungestPerson() {
            var youngest = this[0];
        for (var person = 1; person < this.length; person += 1) {
            if (this[person].age < youngest.age) {
                youngest = this[person];
        return youngest;
    };
    ...