Nodejs Array Extract extract(field)

Here you can find the source of extract(field)

Method Source Code

/**/*w  w w. ja v a 2  s  . c o  m*/
 * Extracts a new array from the czrent one, iterating over the objects in the array, extracting the field
 * 
 * @param String the name of the field 
 * @return Returns a new array containing only the fields (if defined) with the given name of objects in this array
 */
Array.prototype.extract = function(field) {
   var newArray = [];
   for (var i = 0; i < this.length; i++) {
      if (this[i][field] != undefined) {
         newArray.push(this[i][field]);
      }
   }
   return newArray;
};

Related

  1. extract(attribute)
    "use strict";
    Array.prototype.extract = function(attribute) {
      var newArr = [];
      for (var i = 0; i < this.length; i++) {
        newArr.push(this[i][attribute]);
      return newArr;
    
  2. extract(predicate)
    Array.prototype.extract = function(predicate) {
        var removed = [];
        if (this.length===0 || !predicate || typeof predicate !== 'function') {
        return removed;
        var idx = 0;
        while(idx < this.length) {
            if (predicate(this[idx])) {
                removed.push(this[idx]);
    ...