Nodejs Array Compact compacted()

Here you can find the source of compacted()

Method Source Code

Array.prototype.compacted = function () {
    var tmp = [];
    for (var i = 0; i < this.length; i++) {
        if (this[i] !== undefined && this[i] !== null && this[i] !== false) {
            tmp.push(this[i]);/*w  ww .  j a  v a 2 s  . c o m*/
        }
    }
    return tmp;
};

Related

  1. compact()
    Array.prototype.compact = function() {
      return this.reduce(function(res, el) {
        if(el !== null) {
          res.push(el);
        };
        return res;
      }, [])
    
  2. compact()
    Array.prototype.compact = function() {
        return this.filter(function (i) {
            return !!i;
        });
    };
    
  3. compact()
    Array.prototype.compact = function() {
        var comp = [];
        for (var i = 0;i < this.length; i++) {
            if (this[i]) {
                comp.push(this[i]);
        return comp;
    
  4. compact(deleteValue)
    Array.prototype.compact = function(deleteValue) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == deleteValue) {
          this.splice(i, 1);
          i--;
      return this;
    };
    ...
    
  5. compact(fn)
    Array.prototype.compact = function(fn) {
      for (var i = 0; i < this.length; i++)
        if (this[i] == null) {
          this.splice(i, 1);
      return this;
    
  6. compacted()
    Array.prototype.compacted = function () {
        var tmp = [];
        for (var i = 0; i < this.length; i++) {
            if (this[i] !== undefined && this[i] !== null && this[i] !== false) {
                tmp.push(this[i]);
        return tmp;
    };
    ...