find_exp

Finds the first item in an array that matches a Liquid expression. Unlike find, which compares a property to a value, find_exp lets you write arbitrary conditions using the full Liquid expression syntax.

{% assign expensive = products | find_exp: "product", "product.price > 100" %}
{% log expensive.title %}

Syntax

{{ array | find_exp: item_name, expression }}
Parameter
Description

array

Array of objects to search

item_name

Variable name for the current item inside the expression

expression

Liquid expression that evaluates to truthy/falsy

Return Value

Returns the first item for which the expression evaluates to a truthy value, or null if no item matches.

Examples

Find first product above a price threshold:

{% assign expensive = products | find_exp: "p", "p.price > 50" %}
{% if expensive %}
  {% log "First expensive product: " | append: expensive.title %}
{% endif %}

Find first order with a specific tag:

{% assign vip_order = orders | find_exp: "order", "order.tags contains 'VIP'" %}
{% log vip_order.name %}

Find first out-of-stock variant:

Find first item matching multiple conditions:

Notes

  • The item_name parameter defines how you reference each item inside the expression

  • The expression supports all Liquid operators: ==, !=, >, <, >=, <=, contains, and, or

  • Returns the first matching item only

  • For simple property-to-value comparisons, find is more concise

  • See also: where_exp (returns all matching items, not just the first)

Last updated