Compact Array - Node.js Array

Node.js examples for Array:Array Operation

Description

Compact Array

Demo Code


Array.prototype.compact = function(fn) {
  for (var i = 0; i < this.length; i++)
    if (this[i] == null) {
      this.splice(i, 1);//  w  w  w  .  j a v a 2s .co  m
    }
  return this;
}

Related Tutorials