Skip to content
AlertaChartAlertaScript / docs
AlertaScript / Arrays

Reference

Arrays

Guides and navigation are localized. Built-in reference descriptions and code examples are maintained in English.

Name / SignatureDescriptionReturns
alerta.array.new_floatarray.new(size?, initialValue?)Creates a new array. Optional `size` and `initialValue` match Pine behavior; a negative size, or one past 100,000 elements (Pine's collection limit), stops the script with a runtime error. Pine v6 generic form `array.new<T>(size, init)` is accepted and routes to the matching typed constructor (e.g. `array.new<float>()` → `array.new_float()`).Array
alerta.array.new_intarray.new_int(size?, initialValue?)Creates a new int array. Pine v6 form `array.new<int>(size, init)` is an alias.Array<int>
alerta.array.new_boolarray.new_bool(size?, initialValue?)Creates a new bool array. Pine v6 form `array.new<bool>(size, init)` is an alias.Array<bool>
alerta.array.new_stringarray.new_string(size?, initialValue?)Creates a new string array. Pine v6 form `array.new<string>(size, init)` is an alias.Array<string>
alerta.array.new_colorarray.new_color(size?, initialValue?)Creates a new color array.Array<color>
alerta.array.new_linearray.new_line(size?, initialValue?)Creates a new line-handle array.Array<line>
alerta.array.new_linefillarray.new_linefill(size?, initialValue?)Creates a new linefill-handle array.Array<linefill>
alerta.array.new_boxarray.new_box(size?, initialValue?)Creates a new box-handle array.Array<box>
alerta.array.new_labelarray.new_label(size?, initialValue?)Creates a new label-handle array.Array<label>
alerta.array.new_tablearray.new_table(size?, initialValue?)Creates a new table-handle array.Array<table>
alerta.array.getarray.get(id, index)Returns the element at index. An index past either end stops the script with an error; in a //@version=6 script a negative index counts from the end (-1 is the last element).any
alerta.array.setarray.set(id, index, value)Sets an element at index. An index past either end stops the script with an error; in a //@version=6 script a negative index counts from the end (-1 is the last element).void
alerta.array.pusharray.push(id, value)Appends value to array.void
alerta.array.poparray.pop(id)Removes and returns the last element. On an empty array it stops the script with a runtime error ("Cannot use pop() if array is empty."), as in Pine: check `array.size(id) > 0` first.any
alerta.array.shiftarray.shift(id)Removes and returns the first element. On an empty array it stops the script with a runtime error ("Cannot use shift() if array is empty."), as in Pine: check `array.size(id) > 0` first.any
alerta.array.unshiftarray.unshift(id, value)Prepends value to array.void
alerta.array.sizearray.size(id)Returns number of elements in array.int
alerta.array.insertarray.insert(id, index, value)Inserts value at index. An index past the end stops the script with an error; in a //@version=6 script a negative index counts from the end.void
alerta.array.removearray.remove(id, index)Removes and returns element at index. An index past either end stops the script with an error; in a //@version=6 script a negative index counts from the end (-1 is the last element).any
alerta.array.cleararray.clear(id)Clears all elements in an array.void
alerta.array.firstarray.first(id)Returns the first element of an array (series-aware). On an empty array it stops the script with a runtime error, as in Pine: check `array.size(id) > 0` first.any
alerta.array.avgarray.avg(id)Returns the average of numeric values in the array.float
alerta.array.minarray.min(id, nth?)Returns the minimum numeric value in the array, or the nth smallest when nth is given.float
alerta.array.indexofarray.indexof(id, value)Returns the index of a value in the array or -1 if not found (supports series value lookups).int
alerta.array.lastindexofarray.lastindexof(id, value)Returns the last index of a value in the array or -1 if not found.int
alerta.array.sortarray.sort(id, order?)Sorts elements in the array in ascending or descending order: numbers by value, strings by character code; na elements go last (first when descending).void
alerta.array.sumarray.sum(id)Returns the sum of numeric values in the array.float
alerta.array.maxarray.max(id, nth?)Returns the maximum numeric value in the array, or the nth largest when nth is given.float
alerta.array.lastarray.last(id)Returns the last element of the array. On an empty array it stops the script with a runtime error, as in Pine: check `array.size(id) > 0` first.any
alerta.array.slicearray.slice(id, begin, end?)Returns a view of a portion of an array: an element written in the slice is written in the array, and the other way round, until either changes its size. Bounds past the array stop the script.Array
alerta.array.copyarray.copy(id)Returns a shallow copy of an array structure.Array
alerta.array.reversearray.reverse(id)Reverses an array structure in place.void
alerta.array.joinarray.join(id, separator?)Creates and returns a new string by concatenating all of the elements in an array, separated by commas or a specified separator string.string
alerta.array.fillarray.fill(id, value, index_from?, index_to?)Sets elements to a static value — the whole array, or only the [index_from, index_to) sub-range when bounds are given (index_to is exclusive).void
alerta.array.includesarray.includes(id, value)Returns true if array contains value, false otherwise.bool
alerta.array.absarray.abs(id)Returns a new array containing the absolute value of each numeric element.Array<int|float>
alerta.array.everyarray.every(id)Returns true if all elements are truthy.bool
alerta.array.somearray.some(id)Returns true when at least one array element is truthy.bool
alerta.array.binary_searcharray.binary_search(id, value)Searches a sorted numeric array and returns found index, or -1.int
alerta.array.binary_search_leftmostarray.binary_search_leftmost(id, value)Returns the first matching index in a sorted numeric array, or the index immediately left of the insertion point.int
alerta.array.binary_search_rightmostarray.binary_search_rightmost(id, value)Returns the last matching index in a sorted numeric array, or the index immediately right of the insertion point.int
alerta.array.fromarray.from(v1, v2, ...)Creates a new array from provided values.Array
alerta.array.concatarray.concat(target, source)Appends all elements from source array into target array, and returns the target so the call can be used as an expression.Array (the mutated target)
alerta.array.rangearray.range(id)Returns max(array) - min(array).float
alerta.array.stdevarray.stdev(id, biased?)Returns standard deviation of numeric values in array. biased=true (default) = population (÷n); biased=false = sample (÷n-1).float
alerta.array.variancearray.variance(id, biased?)Returns variance of numeric values in array. biased=true (default) = population (÷n); biased=false = sample (÷n-1).float
alerta.array.covariancearray.covariance(a, b, biased?)Returns covariance between two numeric arrays. biased=true (default) = population (÷n); biased=false = sample (÷n-1).float
alerta.array.medianarray.median(id)Returns median of numeric values in array.float
alerta.array.modearray.mode(id)Returns most frequent numeric value in array.float
alerta.array.percentile_nearest_rankarray.percentile_nearest_rank(id, percentage)Returns nearest-rank percentile from array values.float
alerta.array.percentile_linear_interpolationarray.percentile_linear_interpolation(id, percentage)Returns interpolated percentile from array values.float
alerta.array.percentrankarray.percentrank(id, index)Returns the percent rank (0..100) of the element at index: the share of the other elements at or below it.float
alerta.array.sort_indicesarray.sort_indices(id, order?)Returns new array containing indices sorted by values.Array
alerta.array.standardizearray.standardize(id)Returns z-score standardized values as a new array.Array
alerta.order.ascendingorder.ascending → const stringAscending or descending collection sort order. Use order.ascending as a value, without parentheses.const string
alerta.order.descendingorder.descending → const stringAscending or descending collection sort order. Use order.descending as a value, without parentheses.const string
AlertaScript

No results found.

Search by name, alias, or keyword.