> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext/arr.removevalue.md).

# arr.removeValue()

{% hint style="info" %} <mark style="color:yellow;">**removes specific value**</mark> from array.
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}

```javascript
/**
 * remove specific `value` from the array.
 * @example
 * import array_removeValue from './.../array_removeValue.mjs';
 * Object.assign(Array.prototype, array_removeValue);
 * @mixin
 */
const array_removeValue = {

    /**
     * remove specific `value` from the array.
     * @example
     * const arr = [1, 2, 1, 3, 1, 4]
     * arr.removeValue(1)     // [ 2, 3, 4 ]
     * @param value {*} the value to be removed
     */
    removeValue(value) {
        return this.filter(x => x !== value);
    },

};

export default array_removeValue;
```

💈範例：

```javascript
import array_removeValue from '../objects/mixin/array_removeValue.mjs';
Object.assign(Array.prototype, array_removeValue);

const arr = [1, 2, 1, 3, 1, 4]
arr.removeValue(1)                // [ 2, 3, 4 ]
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] JS.info ⟩ [EventMixin](https://javascript.info/mixins#eventmixin)
  {% endtab %}

{% tab title="🗣 討論" %}

* [How can I remove a specific item from an array?](https://stackoverflow.com/a/5767357/5409815)
  {% endtab %}

{% tab title="👥 相關" %}

* [arr.filter()](/web/js/val/builtin/arr/method/arr.filter.md) - remove undefined, nullish, [holes](/web/js/val/builtin/arr/sparse.md),  ... from array.
* [arr.removeUndefined()](/web/js/val/builtin/arr/ext/arr.removeundefined.md)
* [Broken mention](broken://pages/CeORRm8r5BEIy9IyajWP)
* arr.[filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) ignores "[holes](/web/js/val/builtin/arr/sparse.md)" in array.
  {% endtab %}
  {% endtabs %}

## Archive

{% tabs %}
{% tab title="1" %}

* replit ⟩ array ⟩ [removeAll()](https://replit.com/@pegasusroe/JS-array-removeAll#ArrayTools.mjs)

```javascript
/**
 * common tools for Array
 * @mixin
 */
const ArrayTools = {

    /**
     * remove every `value` from the array IN PLACE. ⭐️ 
     * @example
     * // extend Array by mixin
     * Object.assign(Array.prototype, ArrayTools);
     * const a = [1, 2, 1, 3, 1, 4];
     * a.removeAll(1);      // [ 2, 3, 4 ]
     * @param value {*} the value to be removed
     */
    removeAll(value) {
        for (let i = 0; i < this.length; i++) {
            if (this[i] === value) {
                this.splice(i, 1);        // remove one item (in place)
                i -= 1;                   // keep i the same in the next loop
            }
        }
    }

};
```

💈範例：

```javascript
const a = [1, 2, 1, 3, 1, 4];
Object.assign(Array.prototype, ArrayTools);
a.removeAll(1);
a;                // [2,3,4]
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}
