Subarray()

Summary

Extracts a number of elements from an array.

Syntax

sub_array = Subarray(array my_array, integer start, integer count)

Argument Contents
my_array The input array
start The position of the first element extracted
count The number of elements extracted

Returns

An array containing the specified elements of my_array, or null, if start and count do not specify any elements.

Notes

  • If start is null, Subarray() extracts from the beginning of my_array.

  • If count is null, Subarray() returns all the elements of the array beginning with start.

  • Subarray() does not modify my_array; it creates a new array containing a subset of the elements.

Example

array1 = {1, 2, {3, 4, 5}, {6, 7}, 8, 9}
sub = Subarray(array1, 4, 2) // sub = {{6, 7}, 8}
x = Subarray(x, 1, 3) // extracts the first three elements of x

Error Codes

Error Type Meaning
Error Start is less than one, or count is less than zero

See Also

Function Summary
ArrayPosition() Finds the position of a sub-array in an array
CopyArray() Makes a copy of the array, including nested sub-arrays, to any depth
ExcludeArrayElements() Removes elements from an array
ExtractArray() Returns the specified sub-array, which must itself be an array
FindStrings() Finds strings in an array that match one or more search specs
InsertArrayElements() Inserts elements into an array