Nodejs Array Where where(predicate)

Here you can find the source of where(predicate)

Method Source Code

// predicate is a method that accepts one parameter and returns a boolean.
Array.prototype.where = function(predicate) {
    var derivedArray = [];
    for (i = 0; i < this.length; i += 1) {
        if (predicate(this[i])) {
            derivedArray.push(this[i]);//from  w w w  .j ava 2s .  c  om
        }
    }
    return derivedArray;
}

Related

  1. where(func)
    Array.prototype.where = function(func) {
      var result = [];
      for (var i = 0; i < this.length; i++)
        if (func(this[i]))
          result.push(this[i]);
      return result;
    };
    
  2. where(func)
    Array.prototype.where = function(func){
      var result = [];
      forEach(this, function (element) {
        if(func(element)){
          result.push(element);
      });
      return result;
    
  3. where(func)
    Array.prototype.where = function (func) {
        var items = [],
            length = this.length;
        for (var i = 0; i < length; i++) {
            if (func(this[i]))
                items.push(this[i]);
        return items.length === 0 ? null : items;
    
  4. where(inclusionTest)
    Array.prototype.where = function (inclusionTest) {
        var results = [];
        for (var i = 0; i < this.length; i++) {
            if (inclusionTest(this[i]))
                results.push(this[i]);
        return results;
    };
    Array.prototype.select = function (projection) {
    ...
    
  5. where(inclusionTest)
    Array.prototype.where = function (inclusionTest) {
        var results = [];
        for (var i = 0; i < this.length; i++) {
            if (inclusionTest(this[i]))
                results.push(this[i]);
        return results;
    };
    
  6. where(predicate)
    Array.prototype.where = function (predicate) {
        if (predicate == null || typeof (predicate) !== 'function') throw new Error('predicate should');
        var result = [];
        for (var i = 0; i < this.length; i++) {
            if (predicate(this[i], i)) result.push(this[i]);
        return result;
    };
    
  7. where(predicate)
    Array.prototype.where = function (predicate) {
        var ret = [];
        for (var i = 0; i < this.length; ++i) {
            if (predicate(this[i], i))
                ret.push(this[i]);
        return ret;
    };
    
  8. where(predicate)
    Array.prototype.where = function(predicate) {
        if (typeof(predicate) != "function") {
            throw new Error("The argument must be a function");
        var arr = [];
        var index = 0;
        var len = this.length;
        for (var i = 0; i < len; i++) {
            if (predicate(this[i])) {
    ...
    
  9. where(predicate, context)
    Array.prototype.where = Array.prototype.filter || function (predicate, context) {
      context = context || window;
      var arr = [];
      var l = this.length;
      for (var i = 0; i < l; i++)
        if (predicate.call(context, this[i], i, this) === true) arr.push(this[i]);
      return arr;
    };