# toStrictArray

### 说明

&#x20;将给定的类数组转化为严格的数组(`非原地`)

### 源码

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

### 用法

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

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

describe('toStrictArray', () => {
  test('toStrictArray should receive an `ArrayLike` and return the `Array`', () => {
    document.body.innerHTML += `
      <div></div>
      <div></div>
    `;
    const received1 = { length: 0 };
    const received2 = {
      0: 'ddzy',
      1: 20,
      length: 2,
    };
    const received3 = document.querySelectorAll('div');
    const received4 = [1, 2, 3, 4];

    const result1 = toStrictArray(received1);
    const result2 = toStrictArray(received2);
    const result3 = toStrictArray(received3);
    const result4 = toStrictArray(received4);

    expect(result1.length).toBe(0);
    expect(result2.length).toBe(2);
    expect(result3.length).toBe(2);
    expect(result4.length).toBe(4);

    expect(result2[0]).toBe(received2[0]);
    expect(result3[0]).toBe(received3[0]);
    expect(result4[0]).toBe(received4[0]);
  });
});
```

{% 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/tostrictarray.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.
