Help:Extension:Arrays

The extension adds a number of parser functions to define, manipulate, and display arrays of data.

Introduction
Arrays are useful for storing and manipulating lists of data, for example to allow an editor to provide a list of items to a template to be automatically linked, using only a single template parameter for any number of items, instead of requiring one parameter for each item.

Because of how the array functions work, each array, once created, constitutes a piece of global state for the current page, able to be accessed by array functions from anywhere else on the page, similar to. features two parser functions ( and  ) that allow for simple array definition and printing, without creating any global state, and  can be used to manipulate lists of data arbitrarily without requiring global state.

Because the array functions create global state, once an array is defined, it can be displayed or modified anywhere else on the page. To avoid confusion, most of the code examples on this page will explicitly define the array they use; this means that in some cases, the same array name will be reused, and multiple code examples might each define the same array with the exact same contents. In actual usage, a given array would only be defined once, and then only redefined if the original value is no longer needed but a modified value is (for example, if only a sorted copy of the array is needed, or a copy of the array with duplicate items removed).

#arraydefine
is the basic method to define a new array. At minimum it requires the name of the array to be defined, and the value(s) to be stored in the array; in addition, a delimiter and certain options can be specified.

The array name can be any string; generally it should be a short, descriptive name, though care should be taken not to select a name that might be confused with other features. For example,  might be a good array name;   probably is not. Optionally, the name can be prefixed or suffixed with a special character to help visually distinguish it from surrounding text; for example,  or.

The delimiter defaults to a comma, but any string (or no string) can be specified, as well as a regex fragment. Whitespace around the delimiter is ignored.

The array values are a list of strings separated by the delimiter.
 * creates an array named "fruits", with the items "apple", "orange", "banana", and "grape".
 * creates an array named "cities", with the items "Berlin, Germany", "Paris, France", and "Montreal, Canada".

A regex fragment can be used for the delimiter, indicated by.
 * defines an array named "days" where items can be separated by either a comma or a semicolon . This is used to group the input into weekdays and days of the weekend, though the array itself doesn't keep that distinction.

A regex delimiter can also be used to split input on newlines, or to split individual characters of the input.
 * defines an array named "seasons" where each item is placed on its own line. Note that by default, printing this array will still result in the items being separated by commas.
 * defines an array named "digits", containing the digits from 0 to 9 as separate items.