Slicing & Converting
Last updated
Take slices of an array or convert it to another shape.
.left(n) → arrayThe first n elements.
.right(n) → arrayThe last n elements.
arr = [1, 2, 3, 4, 5]
log arr.left(2) // [1, 2]
log arr.right(2) // [4, 5].clone() → arrayAn independent deep copy. (Plain = shares a reference; .clone() does not.)
.getKeys(field) → arrayFor an array of objects, plucks field from each element.
people = [{name: "alice"}, {name: "bob"}]
log people.getKeys("name") // ["alice", "bob"].toSet() → setConverts to a set (unique values). Imports osl/set.
.toEntriesObj() → objectTreats the array as a list of [key, value] pairs and builds an object from them.
Arrays also support the universal methods .len (a property), .toStr(), .getType(), .item(i) - see Type & conversion methods.
Last updated
log [["a", 1], ["b", 2]].toEntriesObj() // {a: 1, b: 2}