Arrays¶
Array Methods¶
Arrays have built-in methods accessible via dot notation. No imports required.
Mutating Methods¶
| Method | Description |
|---|---|
.append(value) |
Add element to end of array |
.pop(index=-1) |
Remove and return element at index (default: last) |
.extend(array) |
Append all elements from another array |
.insert(index, value) |
Insert element at specified index |
.remove(value) |
Remove first occurrence of value |
.set(index, value) |
Set element at index |
.clear() |
Remove all elements |
.reverse() |
Reverse array in place |
.sort(reverse=false) |
Sort array in place |
Query Methods¶
| Method | Description |
|---|---|
.length() |
Get number of elements |
.get(index) |
Get element at index |
.find(element) |
Find index of element (-1 if not found) |
.index_of(element) |
Alias for find |
.includes(element) |
Check if element exists (returns boolean) |
.first() |
Get first element |
.last() |
Get last element |
.count(element) |
Count occurrences of element |
.is_empty() |
Check if array is empty |
Transform Methods¶
| Method | Description |
|---|---|
.slice(start, end) |
Get sub-array from start to end |
.chunk(size) |
Split into sub-arrays of given size |
.copy() |
Create shallow copy |
.unique() |
Return array with duplicates removed |
.join(separator="") |
Join elements into string |
.map(func) |
Transform each element with function |
.filter(func) |
Filter elements by predicate function |
Aggregation Methods¶
| Method | Description |
|---|---|
.sum() |
Sum all numeric elements |
.min() |
Get minimum element |
.max() |
Get maximum element |
.every(func) |
Check if all elements satisfy predicate |
.some(func) |
Check if any element satisfies predicate |
Conversion Methods¶
| Method | Description |
|---|---|
.to_string() |
Convert to string representation |
Array slicing¶
Arrays support slice syntax [start:end:step]. Any part can be omitted.
| slicing.rn | |
|---|---|
Array operators¶
+(concatenation)*(repetition)
| operators.rn | |
|---|---|
Array standard library (Legacy)¶
Built-in Methods
Array methods are now built-in on all arrays. The import array module is kept for backwards compatibility but is no longer required.