Nodejs Array Remove by Value removeValue(thing)

Here you can find the source of removeValue(thing)

Method Source Code

/**// ww  w. j av a 2  s.  com
 * 7 kyu: Splicing
 *
 * The object of this kata is to create a function called removeValue that removes all of a certain
 * value from an array using .splice() and then returns the array. If the array is empty or has no 
 * element to remove it should return false.
 * 
 * example:
 *
 * arr = [1, 2, 1, '1', 3]
 * arr.removeValue(1); // returns [2, '1', 3]
 */

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;
}

Related

  1. removeValue(int)
    Array.prototype.removeValue = function(int) {
      var ans = [];
      var count = 0;
      for (i = 0; i < this.length; i++) {
        if (this[i] !== int) {
          ans.push(this[i]);
        } else if (this[i] === int) {
          count++;
      if (count === 0) {
        return false;
      return ans;
    
  2. removeValue(name, value)
    Array.prototype.removeValue = function(name, value){
      try
       var array = $.map(this, function(v,i){
          return v[name] === value ? null : v;
       });
       this.length = 0; 
       this.push.apply(this, array); 
      catch(e)
        console.log(e);
    
  3. removeValue(name, value)
    Array.prototype.removeValue = function(name, value) {
        var array = $.map(this, function(v, i) {
            return v[name] === value ? null : v;
        });
        this.length = 0; 
        this.push.apply(this, array); 
        return this;
    
  4. removeValue(name, value)
    const DATE_FORMAT = 'Do MMM YYYY';
    const DATETIME_FORMAT = 'Do MMM YYYY LT';
    Array.prototype.removeValue = function(name, value){
       var array = $.map(this, function(v,i){
          return v[name] === value ? null : v;
       });
       this.length = 0; 
       this.push.apply(this, array); 
    
  5. 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;
    
  6. removeValue(val)
    Array.prototype.removeValue = function(val) {
      var index = this.indexOf(val);
      if (index > -1) {
        this.splice(index, 1);
    };
    
  7. removeValue(value)
    Array.prototype.removeValue = function(value) {
        for (var n = 0; n < this.length; n++) {
            if (this[n] == value) {
                this.splice(n, 1);
                break;
    
  8. 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;
    ...
    
  9. removeValue(value)
    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(','));