Nodejs Array Select select(f)

Here you can find the source of select(f)

Method Source Code

Array.prototype.select = function(f){
  var newArray = [];
  var temp = '';

  for(var i = 0; i < this.length; i++){
     temp = f(this[i]);/*from ww w . ja  va  2s  .c  o m*/
      if(temp != null || temp!= undefined){
          newArray.push(temp);
      }
  }
  return newArray;
};

Related

  1. select(fields)
    Array.prototype.select = function (fields) {
        return this.map(function (i) {
            var res = {};
            fields.forEach(function (f) {
                res[f] = i[f];
            });
            return res;
        });
    };
    ...
    
  2. 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;
    ...
    
  3. 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;
    };
    ...
    
  4. select(fun)
    Array.prototype.select = function(fun) {
      return this.reduce(function(res, el) {
        if(fun(el)) {
          res.push(el);
        };
        return res;
      }, []);