# Arrays/slices

A slice/array is a sequence of elements. They are zero indexed, not a fixed size and can be modified on the fly.

## Defining a new array

```
[1, 2, 3]
```

## Appending elements to an array

```
[$someArray..., 4]
```

## Removing elements from an array

```
[1, 2, 3].filter($this % 2 == 0)
```

## Accessing by index

```
$someArray[1]
```

Accessing last array index

```
$someArray[len($someArray)-1]
```

## Accessing a range of items

The range index syntax can be a powerful tool: `[start:end]`

The result will be a new array containing the given range of indexes from start to end.

### Take the first 5 items of an array

```
$someArray[0:4]
```

### Take the last 5 items of an array

```
$someArray[ len($someArray)-6 : len($someArray)-1 ]
```


---

# 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://daseldocs.tomwright.me/syntax/arrays-slices.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.
