Tags

Array & Object Tags

{split;input;separator}

Splits input into an array at separator. separator can be an arbitrary string or regex pattern.

NameTypeDescription
inputstringThe string to split.
separatorstringThe separator or pattern to split the string by.
{split;one,two,three;,}          // {[one;two;three]}
{split;woah party tricks;/ +/g} // {[woah;party;tricks]}
{split;one,two,three;/(,)/g} // {[one;,;two;,;three]}, you can use groups to keep the separator in the output array.

{join;array;separator}

Join the items of an array together with the given separator.

NameTypeDefaultDescription
arrayarrayThe array to join.
separatorstring, (space)The separator to use between the items of the array.
{=array;{[one;two;three]}}
{join;{$array};,} // one,two,three

{push return;array;value}

Adds an item to the end of an array.

This will mutate the original array, which is why nothing is returned by default.

NameTypeDescription
arrayarrayThe array to add the item to.
valueanyThe item to add to the array.
returnboolean?Whether to return the modified array
{=array;{[one]}}
{push;{$array};two} // no output
{$array} // {[one;two]}
{push return;{$array};three} // {[one;two;three]}

{pop}

Returns and deletes the last item of an array.

NameTypeDescription
arrayarrayThe array to pop the item from
{=array;{[one;two;three]}}
{pop;{$array}} // three
{$array} // {[one;two]}

{shift}

Returns and deletes the first item of an array.

NameTypeDescription
arrayarrayThe array to shift the item from
{=array;{[one;two;three]}}
{shift;{$array}} // one
{$array} // {[two;three]}

{unshift return;array;value}

Adds an item to the front of an array. Essentially the same as {push} but the item is added to the beginning of the array.

NameTypeDescription
arrayarrayThe array to add the item to.
valueanyThe item to add to the array.
returnboolean?Whether to return the modified array
{=array;{[three]}}
{unshift;{$array};two} // no output
{$array} // {[two;three]}
{unshift return;{$array};one} // {[one;two;three]}

{for;init;iterable;body}

Note

This tag is part of the General expensive group.

Iterates over array items until {break} is encountered or it reaches the end of the array.

NameTypeDescription
initanyValue that will be set before each iteration of the loop, commonly used for assigning the current item to a variable.
iterablearrayThe array to iterate over.
bodystringThe pella code to run for each item in iterable.
{=array;{[one;two;three]}}

// regular format
{for;{=item};{$array};{$item}} // one two three

// block format
[#for;{=item};{$array}]
{$item}
[/for]

{keys;object}

Get the keys of an object. Useful when you want to iterate over the keys or values of an object. Only top-level keys are returned

NameTypeDescription
objectobjectThe object to get the keys of.
{=object.key;value}
{=object.nested.key;value}
{keys;{$object}} // {[key;nested]}

{includes;array;item}

Check whether an array includes an item.

NameTypeDescription
arrayarrayThe array to search in
itemanyThe item to search for.
{=array;{[one;two;three]}}
{includes;{$array};two} // true

{sort reverse;array;key}

Sort an array. Returns a new array and does not mutate the original.

NameTypeDefaultDescription
arrayarrayThe array to sort
keystring?The key to sort by, if the array is an array of objects.
reversebooleanfalsewhether to reverse the array after sorting.

{slice;target;start;end}

Get a slice of an array or string. If end is not specified, it is assumed to be the length of the target.

NameTypeDescription
targetstringThe array or string to get a slice of.
startnumberThe index to start the slice from.
endnumber?The index to end the slice at. If not specified, it is assumed to be the length of the array or string.
{=array;{[one;two;three]}}
{slice;{$array};1} // {[two;three]}
{slice;{$array};1;2} // {[two]}

{index mode;array;value}

Return the index at which a given element can be found in the array. Defaults to the first instance.

NameTypeDescription
arrayarrayThe array to index
valueanyThe value to look for
modestring?An option mode for indexing the array. Can be last to get the last matching index or all to get all matching indexes.

{filter;array;value;operator;key}

Return an array with just the elements that pass a check.

NameTypeDefaultDescription
arrayarrayThe array to filter
valueanyThe value to filter by
operatorstring?The operator to filter by. The available operators are ==, ===, !=, !==, >, >=, <, <=, startswith, endswith, contains, includes, has and matches.
keystring?The key to filter by if the array is an array of objects. If you are filtering an array of objects and want to filter a specific field for a specific value. For example [{name: "Atlas"}, {name: "Gemini"}]

{splice;array;array...}

Combines two or more arrays into one.

NameTypeDescription
arrayarrayThe arrays to combine, can be two or more arrays.
{=first_array;{[one;two;three]}}
{=second_array;{[four;five;six]}}

{splice;{$first_array};{$second_array}} // {[one;two;three;four;five;six]}