Array Filters

append

Appends an item, or another array, onto an array.

Expects: Array

Argument Required Description
string, object, or array required The string, object, or array which will be added to the end of the array.
# If array = ['foo', 'bar', 'baz']
{{ array | append: 'wik' }} # => ['foo', 'bar', 'baz', 'wik']

first

Return the first item in an array.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | first }} # => foo

include

Returns true or false based on whether or not array includes argument.

Expects: Array

Argument Required Description
object required Whatever you want test inclusion of
# If array = ['foo', 'bar', 'baz']
{{ array | include: 'foo' }} # => true
{{ array | include: 'foo' }} # => false

# Sets the value of include (true or false) to variable foo_included
{{ array | include: 'foo' | assign_to: 'foo_included' }}
{% if foo_included %}
  Yay!
{% endif %}

index

Return the item at a particular index in an array.

Expects: Array

Argument Required Description
integer required The index of the desired array item
# If array = ['foo', 'bar', 'baz']
{{ array | index: 1 }} # => bar

join

Join all the items in an array with specified string.

Expects: Array

Argument Required Description
string required The separator which will be used to join all array items
# If array = ['foo', 'bar', 'baz']
{{ array | join: '-' }} # => foo-bar-baz

last

Return the last item in an array.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | last }} # => baz

map

Return an array with the given property pulled from each entry in the passed array.

Expects: Array

Argument Required Description
property required The property to get from each array item
{{ site.navigation | map: title }} # => ['Title of Page 1', 'Title of Page 2, ...]

prepend

Prepends an item, or another array, onto an array.

Expects: Array

Argument Required Description
string, object, or array required The string, object, or array which will be added to the beginning of the array.
# If array = ['foo', 'bar', 'baz']
{{ array | prepend: 'wik' }} # => ['wik', 'foo', 'bar', 'baz']

randomize

Returns a randomly sorted array. This will only create a new random sorting when the site’s cache needs to be rebuilt.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | randomize }} # => ['bar', 'baz', 'foo'] or ['baz', 'foo', 'bar'] or ...

reverse

Reverses the order of the given array.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | reverse }} # => ['baz', 'bar', 'foo']

size

Return the number of items in an array.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | size }} # => 3

sort

Returns a sorted array.

Expects: Array

Argument Required Description
property optional The property on which to sort the items
# If array = ['foo', 'bar', 'baz']
{{ array | sort }} # => ['bar', 'baz', 'foo']
{{ site.navigation | sort: 'title' }} # => Navigation items sorted by title

split

Split a string into an array, splitting on a given string.

Expects: String

Argument Required Description
string required The string which will be used to split the string into an array.
{{ '1,2,3,4' | split: ',' }} # => ['1', '2', '3', '4']

to_sentence

Turns the items of the array into a nicely formatted sentence.

Expects: Array

# If array = ['foo', 'bar', 'baz']
{{ array | to_sentence }} # => foo, bar, and baz

# If array = ['foo', 'bar']
{{ array | to_sentence }} # => foo and bar

# If array = ['foo']
{{ array | to_sentence }} # => foo