Get a FREE Shopify Website Audit Find out more
I design .

I'm Ketan ‐ A Melbourne web designer and developer
with over 20 years of industry experience.

Head icon.

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 %}