Clean and remove element from array - Node.js Array

Node.js examples for Array:Remove Element

Description

Clean and remove element from array

Demo Code

'use strict';/*from  w ww  .j  a va2s  . co m*/

    Array.prototype.clean = function() {
      var new_array = this.filter(function(val) {
       return val !== null && val !== undefined;
      })
      return new_array;
    }

    Array.prototype.remove = function(from, to) {
      var rest = this.slice((to || from) + 1 || this.length);
      this.length = from < 0 ? this.length + from : from;
      return this.push.apply(this, rest);
    };

Related Tutorials