# Arrays

```ruby
# create an empty array
var arr = []

# push objects into the array
arr << "a"            #: ['a']
arr.append(1,2,3)     #: ['a', 1, 2, 3]

# change an element inside the array
arr[2] = "b"          #: ['a', 1, 'b', 3]

# set the value at a specific index in the array (with autovivification)
arr[5] = "end"        #: ['a', 1, 'b', 3, nil, 'end']

# resize the array
arr.resize_to(-1)     #: []

# slice assignment
arr[0..2] = ('a'..'c')...       #: ['a', 'b', 'c']

# indices as arrays
var indices = [0, -1]
arr[indices] = ("foo", "baz")   #: ['foo', 'b', 'baz']

# retrieve multiple elements
var *elems = arr[0, -1]
say elems                #=> ['foo', 'baz']

# retrieve an element
say arr[-1]              #=> 'baz'
```


---

# 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://trizen.gitbook.io/sidef-lang/programming_tasks/a/arrays.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.
