Sidechair

array.join()

Browse the reference

Combines the items of an array into one string, with a separator between them.

Try it in the editor

Each item is turned into text the way str.tostring() does it, so floats show their decimals and na reads as NaN. The default separator is a comma with no space.

It is the quickest way to print an array in a label, tooltip, table cell or alert message.

Syntax

Pine Script
array.join(id: array<int/float/string>, separator: series string (optional)) -> series string
array.join(separator: series string (optional)) -> series string

Arguments

NameTypeDefaultDescription
idarray<int/float/string>requiredThe array whose items are written into one string, in order, with the separator between them.
separatorseries string","Text placed between items.

Returns

series string: A string of all items separated by the separator.

Remarks

  • Only arrays of numbers and strings are accepted; convert other types to text first.

Example

Pine ScriptShow the window in a labelOpen in editor
//@version=6
indicator("array.join: window label", overlay = true)
var win = array.new<string>()
array.push(win, str.tostring(close, "#.##"))
if array.size(win) > 4
    array.shift(win)
if barstate.islast
    label.new(bar_index, high, array.join(win, " | "))

See also

Runs on Sidechair