All Products
Search
Document Center

Server Load Balancer:Array functions

Last Updated:Apr 01, 2026

Array functions let you build, modify, and inspect arrays in EdgeScript. Use them together to implement custom routing logic in Application Load Balancer (ALB).

arr_concat

Joins all elements of an array into a single string, with an optional separator between each element.

Syntax

arr_concat(tbl: Array, sep: String) → String

Parameters

ParameterRequiredDescription
tblYesThe array whose elements to concatenate.
sepNoThe separator string inserted between each element. Defaults to an empty string.

Return value

A string of all elements joined by sep. If sep is omitted, elements are joined with no separator.

Example

d = ['t1', 't2', 't3']
say(arr_concat(d, '&'))
-- Output: t1&t2&t3

arr_insert

Inserts an element into an array at a specified position. See also arr_remove, which removes elements from an array.

Syntax

arr_insert(list: Array, value: Any, pos: Number) → Boolean

Parameters

ParameterRequiredDescription
listYesThe array to insert into.
valueYesThe value to insert. Accepts any type.
posNoThe 1-based index at which to insert. Elements at and after this position shift one position toward the end. Defaults to the end of the array. Cannot be 0.

Edge cases

  • Array indexes start at 1, not 0. pos cannot be 0.

  • If pos is omitted, the element is appended to the end of the array.

Return value

true on success.

Example

tbl_1 = []
arr_insert(tbl_1, '1')      -- tbl_1: ['1']
arr_insert(tbl_1, '3')      -- tbl_1: ['1', '3']
arr_insert(tbl_1, '5')      -- tbl_1: ['1', '3', '5']
arr_insert(tbl_1, '2')      -- tbl_1: ['1', '3', '5', '2']
arr_insert(tbl_1, '6', 1)   -- tbl_1: ['6', '1', '3', '5', '2']
str = arr_concat(tbl_1, '')
say(concat('arr_insert:', str))
-- Output: arr_insert:61352

arr_remove

Removes the element at a specified position from an array and returns it. See also arr_insert, which inserts elements into an array.

Syntax

arr_remove(list: Array, pos: Number) → Any

Parameters

ParameterRequiredDescription
listYesThe array to remove from.
posNoThe 1-based index of the element to remove. Defaults to the last element. Cannot be 0.

Edge cases

  • Array indexes start at 1, not 0. pos cannot be 0.

  • If pos is omitted, the last element is removed and returned.

Return value

The removed element.

Example

tbl_1 = []
arr_insert(tbl_1, '1')   -- tbl_1: ['1']
arr_insert(tbl_1, '3')   -- tbl_1: ['1', '3']
arr_insert(tbl_1, '5')   -- tbl_1: ['1', '3', '5']
arr_insert(tbl_1, '2')   -- tbl_1: ['1', '3', '5', '2']
say(concat('arr_remove:', arr_remove(tbl_1, 2)))
-- Output: arr_remove:3

Removing the element at index 2 returns '3', and the array becomes ['1', '5', '2'].

arr_sort

Sorts the elements of an array in place, from the first index to the last.

Syntax

arr_sort(list: Array, comp: Function) → Boolean

Parameters

ParameterRequiredDescription
listYesThe array to sort.
compNoA comparison function. Must accept two elements and return true if the first element should precede the second. Defaults to ascending ASCII order.

Edge cases

  • If comp is omitted, elements are sorted by ascending ASCII code value. This sort is not stable: elements with equal ASCII rank may swap positions relative to each other.

  • Pass a custom comp function when you need numeric ordering or descending order.

Return value

true on success.

Example

The following example demonstrates default ASCII sorting and a custom numeric descending sort.

tbl_1 = []
arr_insert(tbl_1, '1')
arr_insert(tbl_1, '3')
arr_insert(tbl_1, '5')
arr_insert(tbl_1, '2')

say(concat('remove:', arr_remove(tbl_1, 2)))  -- Output: remove:3
str = arr_concat(tbl_1, '')
say(concat('insert:', str))                   -- Output: insert:152

arr_sort(tbl_1)
str = arr_concat(tbl_1, '')
say(concat('sort:', str))                     -- Output: sort:125

def my_comp(a, b) {
  a = tonumber(a)
  b = tonumber(b)
  if gt(a, b) {
    return true
  }
  return false
}
arr_sort(tbl_1, my_comp)
str = arr_concat(tbl_1, '')
say(concat('sort_comp:', str))               -- Output: sort_comp:521

arr_len

Returns the number of elements in an array.

Syntax

arr_len(arr: Array) → Number

Parameters

ParameterRequiredDescription
arrYesThe array to measure.

Return value

The element count as a numeric value.

Example

d = []
set(d, 1, 'v1')
say(arr_len(d))
-- Output: 1