Nodejs Array Extract extract(attribute)

Here you can find the source of extract(attribute)

Method Source Code

"use strict";//w w w  .j  a  v  a  2s  .co m

Array.prototype.extract = function(attribute) {
   var newArr = [];
   
   for (var i = 0; i < this.length; i++) {
      newArr.push(this[i][attribute]);
   }
   
   return newArr;
}

Related

  1. extract(field)
    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;
    };
    ...
    
  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]);
    ...