# head

### 说明

&#x20;获取指定数组的第`一`个元素

### 源码

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

### 用法

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

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

describe('head tests: ', () => {
  test('head should return the first field that was in origin array', () => {
    const received: number[] = [1, 2, 3, 4, 5];
    const expected = 1;

    const result = head<number>(received);

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

  test('head should return undefined when receive an empty array', () => {
    const received: any[] = [];
    const expected = undefined;

    const result = head<any>(received);

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

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