Nodejs Array Delete by Index deleteItems(ids, filterEmpty = true)

Here you can find the source of deleteItems(ids, filterEmpty = true)

Method Source Code

Array.prototype.deleteItems = function (ids, filterEmpty = true) {
    var result = this.slice();
    if (typeof ids === 'object' && ids.constructor === [].constructor) {

        ids.sort(function (a, b) {
            return b > a;
        }).forEach(function (value) {

            if (filterEmpty) {
                result.splice(value, 1);
            } else {/*from w w w .  ja  va  2  s .com*/
                delete result[value]
            }
            console.log(result);
        });

    }
    console.log(result);
    return result;
};

[1, 2, 3, 4, 5, 6].deleteItems([1, 2, 3], false);

Related

  1. delete()
    Array.prototype.delete = function() { 
        var arr = this;
        var todel = arguments[0];
        if(todel && todel instanceof Array) {
            var arraux = [];
            for(var i=0; i<todel.length;i++) {
                arr.some(function(el, j){
                    if(el == todel[i]){
                        arraux.push(j+'');
    ...
    
  2. delete(index)
    'use strict';
    Array.prototype.delete = function (index) {
        delete this[index];
        this.splice(index, 1);
        return this;
    };
    
  3. deleteAll()
    Array.prototype.deleteAll = function(){
      var arr = this;
      arr.splice(0,arr.length);
    
  4. deleteAt(index)
    Array.prototype.deleteAt = function(index) {
      return this.splice(index, 1);
    };
    
  5. delete_at(from, to)
    Array.prototype.delete_at = 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);
    Array.prototype.delete_if = function(matcher){
      for(var i = 0; i < this.length; i++){
        if(matcher(this[i])) {
          this.delete_at(i)
    ...