Skip to main content

Array Functions

$count()

Signature: $count(array)

Returns the number of items in the array parameter. If the array parameter is not an array, but rather a value of another JSON type, then the parameter is treated as a singleton array containing that value, and this function returns 1.

If array is not specified, then the context value is used as the value of array.

Examples

  • $count([1,2,3,1]) => 4
  • $count("hello") => 1

$append()

Signature: $append(array1, array2)

Returns an array containing the values in array1 followed by the values in array2. If either parameter is not an array, then it is treated as a singleton array containing that value.

Examples

  • $append([1,2,3], [4,5,6]) => [1,2,3,4,5,6]
  • $append([1,2,3], 4) => [1,2,3,4]
  • $append("Hello", "World") => ["Hello", "World"]

$sort()

Signature: $sort(array [, function])

Returns an array containing all the values in the array parameter, but sorted into order. If no function parameter is supplied, then the array parameter must contain only numbers or only strings, and they will be sorted in order of increasing number, or increasing unicode codepoint respectively.

If a comparator function is supplied, then is must be a function that takes two parameters:

function(left, right)

This function gets invoked by the sorting algorithm to compare two values left and right. If the value of left should be placed after the value of right in the desired sort order, then the function must return Boolean true to indicate a swap. Otherwise it must return false.

$distinct()

Signature $distinct(array)

Returns an array containing all the values from the array parameter, but with any duplicates removed. Values are tested for deep equality as if by using the equality operator.