Nodejs Array Remove by Value removeElement(param)

Here you can find the source of removeElement(param)

Method Source Code

/**/*from   w  ww  .  j a v a2 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.
 */


Array.prototype.removeElement = function (param) {
    for(var i = this.length; i--;){
        if (this[i] === param) this.splice(i, 1);
    }
}

var arr = [3,5,3,22,663,11,8,3];
arr.removeElement(3);
console.log(arr);

Related

  1. removeItemsByValue(value)
    Array.prototype.removeItemsByValue =  function(value){
        for(var i = 0 ; i < this.length ; i++){
            if(this[i] == value ){
                this.splice(i,1);
        return this;
    var a = [1,2,3,4,1,2,"1",5,1];
    ...
    
  2. removeOne(el)
    Array.prototype.removeOne = function (el) {
        var index = this.indexOf(el);
        if (index != -1) {
            this.splice(index, 1);
            return true;
    };
    
  3. removeOneByValue(v)
    Array.prototype.removeOneByValue = function(v) {
        for (let i = this.length - 1; i >= 0; i--)
            if (this[i] === v)
                return this.splice(i, 1);
        return this;
    };
    
  4. removeData(oneItem)
    Array.prototype.removeData = function(oneItem)
      var index = dojo.indexOf(this, oneItem);
      if (index != -1)
        return this.splice(index, 1);
      return this;
    
  5. removeEle(ele)
    Array.prototype.removeEle = function(ele){
        var arr = this;
        console.log(arr);
        console.log(ele)
        this.pop(ele);
        return arr;