length is a property (no parentheses); all others are methods.
| Method / Property | Returns | Description |
|---|---|---|
list.length |
Integer |
Number of elements |
list.contains(val) |
Bool |
Whether the list contains an equal value |
list.append(val) |
List |
Appends val in-place; returns the same list |
list.pop() |
any |
Removes and returns the last element |
list.pop(i) |
any |
Removes and returns the element at index i |
list.slice(start, end) |
List |
Returns a new sub-list from start (inclusive) to end (exclusive) |
list.reverse() |
List |
Returns a new reversed copy (does not mutate) |
list.sort() |
List |
Returns a new sorted copy (does not mutate) |
list.join(sep) |
String |
Joins elements into a string using sep as separator |
list.index_of(val) |
Integer |
Index of first occurrence, or -1 if not found |
let nums = [5, 3, 8, 1, 9, 2]
print(nums.sort()) // [1, 2, 3, 5, 8, 9]
print(nums.reverse()) // [2, 9, 1, 8, 3, 5]
print(nums.slice(1, 4)) // [3, 8, 1] (original list is unchanged)
print(nums.length) // 6
let words = ["hello", "world", "foo"]
words.append("bar")
let last = words.pop() // "bar" — removes last element
print(words.join(", ")) // hello, world, foo
print(words.index_of("world")) // 1
Negative indices in pop() count from the end:
let items = [10, 20, 30, 40]
print(items.pop(-1)) // 40
print(items) // [10, 20, 30]