> For the complete documentation index, see [llms.txt](https://docs.videsk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.videsk.io/es-developers/webhooks/helpers/array.md).

# #array

A continuación, podrás encontrar la documentación de como utilizar este helper.

Con `#array` podrás mutar una matriz (`Array`) a la estructura que desees y/o devolver un `Array` válido.

{% hint style="info" %}
Utiliza este helper principalmente cuando el formato debe ser `JSON`.
{% endhint %}

#### Estructura original

```javascript
{
    "elements": [
        {
            "_id": "60cbc69048f3bd7cc732e028",
            "name": "Segment",
            "value": "Customer Service"
        }
    ]
}
```

### Sin modificación del esquema

Por defecto, no es posible seleccionar un `Array` con sintaxis mustache, por lo que puedes usar este helper para retornar un `Array` válido.

{% tabs %}
{% tab title="Con #array" %}
**Sintaxis**

```handlebars
{{#arrray elements}}{{/array}}
```

**Resultado**

```javascript
[
    {
       "_id": "60cbc69048f3bd7cc732e028",
       "name": "Segment",
       "value": "Customer Service"
    }
]
```

{% endtab %}

{% tab title="Sin #array" %}
**Sintaxis**

```handlebars
{{elements}}
```

**Resultado**

```json
[object Object]
```

{% endtab %}
{% endtabs %}

### Modificando el esquema

Este helper no solo ayuda a retonar un Array válido, si no que también modificar su estructura cuando sus valores son objetos (`Object`). Para ello deberás escribir dentro del helper `#array`.

```handlebars
{{#array elements}}  {{/array}}
-------------------^ (escribe dentro del helper)
```

Por ejemplo, si necesitas que el resultado sea un `Array` de objetos, donde cada objeto contenga un `id` y `value` deberás escribir lo siguiente:

{% tabs %}
{% tab title="Array de objetos" %}
**Sintaxis**

{% code title="Usando comillas dobles" %}

```handlebars
{{#array elements}}{ "id": "{{_id}}", "name": "{{value}}" }{{/array}}
```

{% endcode %}

**Resultado**

```json
[
    {
        "id": "60cbc69048f3bd7cc732e028",
        "name": "Customer Service"
    }
]
```

De esta forma se transformó el objeto original pero el resultado sigue siendo un `Array` con objetos.

{% hint style="info" %}
También puedes complementar helpers en conjunto como `#array` con `parser`.

**De esta forma te aseguras que el valor sea válido y no ocurra que un `object`, `array`, `boolean`, etc. esté entre comillas dobles.**
{% endhint %}

{% code title="Usando parser" %}

```handlebars
{{#array elements}}{ "id": {{parser _id}}, "name": {{parser value}} }{{/array}}
```

{% endcode %}
{% endtab %}

{% tab title="Array simple" %}
{% hint style="warning" %}
Solo podrás definir una `key` de cada objeto si es un `Array` de objetos.
{% endhint %}

**Sintaxis**

```handlebars
{{#array fields}}name{{/array}}
```

**Resultado**

```json
["Customer Service"]
```

De esta forma se transformó consigue un `Array` simple sin objetos.
{% endtab %}
{% endtabs %}

##


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.videsk.io/es-developers/webhooks/helpers/array.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
