Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

10.4 Array and object functions

Arrays are 0-based; a negative index counts from the end.


at

at(array, i) → the item at i, null when out of range.

at(tags, 0)
at([3, 1, 2], -1)          → 2
at([3, 1, 2], 5)           → null
get(at(join_1, 0), "groupe", null)       -- the first joined row's field

slice

slice(array, start [, length]) → the sub-array from start, up to length items.

slice([3, 1, 2], 1)        → [1,2]
slice([3, 1, 2], -2, 1)    → [1]

reverse

reverse(x) → the array (or string) reversed.

reverse(tags)
reverse("Ab")              → "bA"

sort_array

sort_array(array [, "asc" | "desc"]) → a sorted copy; items must be comparable.

sort_array([3, 1, 2], "desc")      → [3,2,1]

unique

unique(array) → the distinct items, the first occurrence kept.

unique([1, 1, 2])          → [1,2]

flatten

flatten(array) → the array flattened by one level.

flatten([[1], [2, [3]]])   → [1,2,[3]]

range

range(start, end [, step]) → the integers from start up to, not including, end; at most 1,000,000 items.

range(0, 6, 2)             → [0,2,4]
on values [{m: 0}] | derive m = range(0, 12) | unwind m        -- twelve rows

keys

keys(o) → the keys of an object, sorted.

keys(profile)              → ["country","score"]

values

values(o) → the values of an object, in key order.

values({"k": 1})           → [1]

values is also the source of literal rows, on values [{…}]. In stage position it is a source; in an expression it is this function.

get

get(o, key [, default]) → the value under key, including keys that are not identifiers; default (or null) when absent.

get(meta, "display name", "")
get(o, "z", 0)             → 0
get(coalesce(at(o, 0), {}), "path", "")

has

has(o, key) → whether key is present.

has(profile, "score")

merge

merge(o1, o2, …) → a shallow merge, later objects winning; null arguments skipped.

merge(profile, {"level": 2})
merge({"k": 1}, {"z": 2}, null)    → {"k":1,"z":2}

Membership. x in array and x not in array are operators: "dev" in tags, status in ["paid", "pending"]. contains(array, x) is the function form.