Skip to main content

find_index

array | find_index: string, string
returns number

Returns the index of the first item in an array with a specific property value.

This requires you to provide both the property name and the associated value.

{% assign index = collection.products | find_index: 'vendor', "Polina's Potent Potions" %}

{{ index }}

Output

0
Anchor to Returns `nil` when no items match the specified property value.

Returns nil when no items match the specified property value.

{% assign index = collection.products | find_index: 'vendor', "Polina's Potions" %}

{{ index | default: "No index found" }}

Output

No index found
Was this page helpful?