Javascript Array compact(deleteValue)

Description

Javascript Array compact(deleteValue)

Array.prototype.compact = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {
      this.splice(i, 1);/*from  w w w .j  ava2  s.c  o  m*/
      i--;
    }
  }
  return this;
};

Javascript Array compact(fn)


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



PreviousNext

Related