Nodejs Array Select select(func)

Here you can find the source of select(func)

Method Source Code

Array.prototype.select = function (func) {
    var length = this.length,
        items = [];//from   w  ww . j a v  a2s.c  o  m

    for (var i = 0; i < length; i++) {
        items.push(func(this[i]));
    }

    return items;
}

Related

  1. select(f)
    Array.prototype.select = function(f){
      var newArray = [];
      var temp = '';
      for(var i = 0; i < this.length; i++){
         temp = f(this[i]);
          if(temp != null || temp!= undefined){
              newArray.push(temp);
      return newArray;
    };
    
  2. select(fields)
    Array.prototype.select = function (fields) {
        return this.map(function (i) {
            var res = {};
            fields.forEach(function (f) {
                res[f] = i[f];
            });
            return res;
        });
    };
    ...
    
  3. select(filter)
    Array.prototype.select = function(filter)
      var newArr = []
      for (var i = 0; i< this.length; i++) {
        if(filter(this[i])){
          newArr.push(this[i]);
      return newArr;
    ...
    
  4. select(fnCallback)
    Array.prototype.select = function(fnCallback) {
        var value = Array();
        for (var elementIndex in this) {
            if (this.hasOwnProperty(elementIndex)) {
                value.push(fnCallback.apply(this[elementIndex], [elementIndex]));
        return value;
    };
    ...
    
  5. select(fun)
    Array.prototype.select = function(fun) {
      return this.reduce(function(res, el) {
        if(fun(el)) {
          res.push(el);
        };
        return res;
      }, []);
    
  6. select(lambda)
    Array.prototype.select = function(lambda) {
        if (lambda == undefined) {
            return this;
        } else {
            result = [];
            for (i = 0; i < this.length; i++) {
                if (lambda(this[i])) {
                    result.push(this[i]);
            return result;
    };
    
  7. select(predicate)
    Array.prototype.select = function(predicate){
        var r = []
        for(var n = 0; n < this.length; n++) {
            if(predicate(this[n])){
                r.push(this[n]);
        return r;
    };
    ...
    
  8. select(projection)
    Array.prototype.select = function (projection) {
        var results = [];
        for (var i = 0; i < this.length; i++) {
            results.push(projection(this[i]));
        return results;
    };
    var children = [{ id: 1, Name: "Rob" }, { id: 2, Name: "Sansa" }, { id: 3, Name: "Arya" }, { id: 4, Name: "Brandon" }, { id: 5, Name: "Rickon" }];
    var filteredChildren = children.where(function (x) {
    ...
    
  9. select(selectFunction)
    Array.prototype.select = function(selectFunction) {
        return this.inject([], function(result, element) {
            if (selectFunction(element)) {
                result.push(element);    
            return result;
        });
    };