All Products
Search
Document Center

ApsaraVideo VOD:Array functions

Last Updated:Jul 10, 2026

Array functions allow you to concatenate, insert, remove, sort, and count elements in arrays.

arr_concat

Concatenates strings in an array by using a specified delimiter.
Item Description
Syntax arr_concat(tbl, sep)
Parameter
  • tbl: the array whose elements you want to concatenate.
  • sep (optional): the delimiter used to concatenate strings. Default value: empty string.
Example
d = ['t1','t2','t3']
say(arr_concat(d, '&'))
Return value Returns the concatenated string. In this example, t1&t2&t3 is returned.

arr_insert

Inserts an element into an array.
Item Description
Syntax arr_insert(list, value, [pos])
Parameter
  • list: the array into which you want to insert an element.
  • value: the element to insert. Data type: any type.
  • pos (optional): the position at which to insert the element. The value must be a non-zero numeric value. Array indexes start from 1. Elements after the specified position are shifted one position toward the end. If you do not specify this parameter, the element is appended to the end of the array.
Example
tbl_1 = []
arr_insert(tbl_1, '1')
arr_insert(tbl_1, '3')
arr_insert(tbl_1, '5')
arr_insert(tbl_1, '2')
arr_insert(tbl_1, '6', 1)
str = arr_concat(tbl_1, '')
say(concat('arr_insert:', str))
Return value Returns true. In this example, arr_insert:61352 is returned.

arr_remove

Removes an element at the specified position from an array and returns the removed element. If you do not specify the pos parameter, the last element is removed.
Item Description
Syntax arr_remove(list, [pos])
Parameter
  • list: the array from which you want to remove an element.
  • pos (optional): the position of the element to remove. Data type: numeric.
Example
tbl_1 = []
arr_insert(tbl_1, '1')
arr_insert(tbl_1, '3')
arr_insert(tbl_1, '5')
arr_insert(tbl_1, '2')
say(concat('arr_remove:', arr_remove(tbl_1, 2)))
Return value Returns the removed element. In this example, arr_remove:3 is returned.

arr_sort

Sorts elements in an array in a specified order.
  • If you specify the comp parameter, it must be a function that accepts two array elements as parameters. The function returns true if the first element should be placed before the second element.
  • If you do not specify the comp parameter, elements are sorted by ASCII codes in ascending order. This sorting algorithm is unstable and may change the original order of elements with equal values.
Item Description
Syntax arr_sort(list, [comp])
Parameter
  • list: the array to sort.
  • comp (optional): a custom comparison function.
Example
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)))
str = arr_concat(tbl_1, '')
say(concat('insert:', str))
arr_sort(tbl_1)
str = arr_concat(tbl_1, '')
say(concat('sort:', str))
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))
Return value Returns true. In this example, the following values are returned:
remove:3
insert:152
sort:125
sort_comp:521

arr_len

Returns the number of elements in an array.
Item Description
Syntax arr_len(arr)
Parameter arr: the array.
Example
d = []
set(d, 1, 'v1')
say(arr_len(d))
Return value Returns the number of elements in the array. Data type: numeric. In this example, 1 is returned.