# \_join

### 说明

&#x20;将数组中的所有元素转换为由 `separator` 分隔的字符串

### 源码

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

### 用法

{% code title="\_join.test.ts" %}

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

describe('Method _join test:', () => {
  test('_join() should return the empty string when receive an empty array', () => {
    const received = {
      arr: [],
      separator: '',
    };
    const expected = '';

    const result = _join(received.arr, received.separator);

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

  test('_join() should return the composed string when receive an array maked by number', () => {
    const received = {
      arr: [1, 2, 3, 4, 5],
      separator: '',
    };
    const expected = '12345';

    const result = _join(received.arr, received.separator);

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

  test('_join() can config your own separator', () => {
    const received = {
      arr: ['a', 'b', 'c', 'd', 'e'],
      separator: '-',
    };
    const expected = 'a-b-c-d-e';

    const result = _join(received.arr, received.separator);

    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/_join.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.
