# 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](https://lochiwei.gitbook.io/web/js/val/builtin/arr/method/arr.filter "mention") - remove undefined, nullish, [holes](https://lochiwei.gitbook.io/web/js/val/builtin/arr/sparse),  ... from array.
* [arr.removeundefined](https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext/arr.removeundefined "mention")
* [Broken link](https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext/broken-reference "mention")
* arr.[filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) ignores "[holes](https://lochiwei.gitbook.io/web/js/val/builtin/arr/sparse)" 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext/arr.removevalue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
