Nodejs Array Remove by Value removeValue(value)

Here you can find the source of removeValue(value)

Method Source Code

//Problem 2. Remove elements
///*from  ww w  . j  av  a  2 s.  c  om*/
//Write a function that removes all elements with a given value.
//    Attach it to the array type.
//    Read about prototype and how to attach methods.
//
//    var arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'];
//    arr.remove(1); //arr = [2,4,3,4,111,3,2,'1'];

var i,
    len,
    arr = [1, 2, 1, 4, 1, 1, 3, 4, 1, 111, 3, 2, 1, '1'];

Array.prototype.removeValue = function(value) {

    for (i = 0, len = this.length; i < len; i += 1) {
        if (this[i] === value) {
            this.splice(i, 1);
            i -= 1;
        }
    }
}

arr.removeValue(1);
console.log(arr.join(','));

Related

  1. removeValue(thing)
    Array.prototype.removeValue = function(thing) {
      for (var i = 0; i < this.length; i++) {
        if(this[i] == thing) {
          this.splice(i, 1);
      return this;
    
  2. removeValue(thing)
    Array.prototype.removeValue = function(thing) {
      if (this.indexOf(thing) === -1) return false;
      var i;
      while ((i = this.indexOf(thing)) > -1) this.splice(i, 1);
      return this;
    
  3. removeValue(val)
    Array.prototype.removeValue = function(val) {
      var index = this.indexOf(val);
      if (index > -1) {
        this.splice(index, 1);
    };
    
  4. removeValue(value)
    Array.prototype.removeValue = function(value) {
        for (var n = 0; n < this.length; n++) {
            if (this[n] == value) {
                this.splice(n, 1);
                break;
    
  5. removeValue(value)
    Array.prototype.removeValue = function (value) {
      var index = -1;
      for (var i = 0; i < this.length; i++) {
        if (this[i] == value) {
          this.splice(i,1);
          index = i;
      return index;
    ...
    
  6. removeId(obj)
    Array.prototype.removeId = function(obj) {
      for(var i = 0; i < this.length; i++){
        if(this[i].toString() === obj.toString()){
          this.splice(i, 1);
      return this;
    };
    
  7. removeItem(obj)
    Array.prototype.removeItem = function(obj) {
        var index = this.indexOf(obj);
        if (-1 === index)return;
        this.splice(index, 1);
    };
    
  8. removeItemByID(element)
    Array.prototype.removeItemByID = function(element)
        var found;
        for (var i = 0; i < this.length; i++)
            if (this[i].id == element.id)
                found = this[i];
                break;
    ...
    
  9. removeItems(value)
    Array.prototype.removeItems = function(value) {
        return this.filter(filterInput);
        function filterInput(v) {
            return v != value;
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    console.log(arr.removeItems(1));
    var arr = ['hi', 'bye', 'hello' ];
    ...