Shopify Tips

Liquid tip: Removing null values from an array

← Blog

Here’s a little trick I learned for removing null or empty values from an array in Shopify’s liquid.

By using the compact filter will return a nice clean array. Using this filter is especially useful when working with comma-separated lists, like in the example below.

{% assign my_list = "one,two,three,four,five,,six,seven" %}
{% assign my_array = my_list | split: ',' | compact %}

Subscribe to my newsletter

Sign up to get my latest blog articles direct to your inbox.