> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sensecode.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Arrays

> Literals, indexing, mutation, and the array-related builtins.

## Literals and indexing

```sns theme={null}
scores = [1, 2, 3]
print(scores[0])     # 1
scores[0] = 10
print(scores)         # [10, 2, 3]
```

Arrays are heterogeneous (elements don't need matching types), 0-indexed,
and mutable in place. Indexing with a non-`Int` or an out-of-range index is
a runtime error, not a silent `nil`:

```sns theme={null}
scores["x"]    # error: index must be Int, got String
scores[99]     # error: index 99 out of bounds
```

## Typed array declarations

```sns theme={null}
users: Array<String> = ["alice", "bob"]
```

`Array<T>` checks every element against `T` when the annotation is
present — see [Values & Types](/language/values-and-types) for how
annotation-checking works generally.

## Concatenation

`+` concatenates two arrays (the same operator used for string
concatenation and numeric addition — see
[operators](/language/values-and-types#operators)):

```sns theme={null}
print([1, 2] + [3, 4])   # [1, 2, 3, 4]
```

## Builtins

<Frame>
  | Builtin                                       | Does                                    |
  | --------------------------------------------- | --------------------------------------- |
  | `len(x)`                                      | length of an `Array` or `String`        |
  | `push(array, x)`                              | appends `x` in place, returns the array |
  | `range(a)` / `range(a,b)` / `range(a,b,step)` | builds an `Array<Int>`                  |
</Frame>

```sns theme={null}
xs = [1]
push(xs, 2)
push(xs, 3)
print(xs)          # [1, 2, 3]
print(len(xs))     # 3
```

## What's not here yet

No slicing (`xs[1:3]`), no built-in `map`/`filter`/`reduce`, no
dictionaries/maps/objects — the value model is deliberately minimal in
Phase 1 (see [Roadmap](/roadmap)). A `for` loop plus `if` covers the same
ground for now:

```sns theme={null}
evens = []
for n in range(0, 10):
    if n % 2 == 0:
        push(evens, n)
print(evens)   # [0, 2, 4, 6, 8]
```

## Continue

<CardGroup cols={2}>
  <Card title="Modules" icon="folder-tree" href="/language/modules">
    Splitting a program across files.
  </Card>

  <Card title="Grammar reference" icon="terminal" href="/reference/grammar">
    The complete EBNF, including array literal syntax.
  </Card>
</CardGroup>
