# pullAll

### 说明

&#x20;移除数组 `arr` 中所有和给定值相等的元素, 原地操作

### 源码

<https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/array/pullAll>

### 用法

{% code title="pullAll.test.ts" %}

```typescript
import { pullAll } from "../../utility/array/pullAll";


describe('pullAll tests...', () => {
  test('Method pullAll should receive an array composed of number and return the filtered array', () => {
    const received = {
      origin: [1, 2, 3, 1, 2, 3],
      selector: [2, 3],
    };
    const expected = {
      isEqual: true,
      result: [1, 1],
    };

    const result = pullAll<number>(received.origin, received.selector);

    expect(result === received.origin).toBe(expected.isEqual);

    result.forEach((v, i) => {
      expect(v).toBe(expected.result[i]);
    });
  });

  test('Method pullAll should receive an array composed of plain object and return the filtered array', () => {
    interface IOriginParams {
      name: string,
      age: number,
    };

    const received = {
      origin: [
        {
          name: 'duan',
          age: 21,
        },
        {
          name: 'zhao',
          age: 22,
        },
        {
          name: 'duan',
          age: 21,
        },
      ],
      selector: [
        {
          name: 'duan',
          age: 21,
        },
      ],
    };
    const expected = {
      isEqual: true,
      result: [
        {
          name: 'duan',
          age: 21,
        },
        {
          name: 'zhao',
          age: 22,
        },
        {
          name: 'duan',
          age: 21,
        },
      ],
    };

    const result = pullAll<IOriginParams>(received.origin, received.selector);

    expect(result === received.origin).toBe(expected.isEqual);

    expect(result.length).toBe(expected.result.length);
  });

  test('Method pullAll should receive an array composed of mixed value and return the filtered array', () => {
    const received = {
      origin: [
        0,
        19980808,
        'duanzhaoyang',
        false,
        null,
        undefined,
        Symbol('a'),
        function () { },
        {},
        [],
      ],
      selector: [false, undefined, 19980808, []],
    };
    const expected = {
      isEqual: true,
      result: [
        0,
        'duanzhaoyang',
        null,
        Symbol('a'),
        function () { },
        {},
        [],
      ],
    };

    const result = pullAll<any>(received.origin, received.selector);

    expect(result === received.origin).toBe(expected.isEqual);

    expect(result.length).toBe(expected.result.length);
  });
});
```

{% endcode %}


---

# 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://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-array/pullall.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.
