find
array | find: string, string
Returns 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 product = collection.products | find: 'vendor', "Polina's Potent Potions" %}
{{ product.title }}
Code
{% assign product = collection.products | find: 'vendor', "Polina's Potent Potions" %}
{{ product.title }}Data
{
"collection": {
"products": [
{
"title": "Blue Mountain Flower",
"vendor": "Polina's Potent Potions"
},
{
"title": "Charcoal",
"vendor": "Ted's Apothecary Supply"
},
{
"title": "Crocodile tears",
"vendor": "Polina's Potent Potions"
},
{
"title": "Dandelion milk",
"vendor": "Clover's Apothecary"
},
{
"title": "Draught of Immortality",
"vendor": "Polina's Potent Potions"
},
{
"title": "Dried chamomile",
"vendor": "Clover's Apothecary"
},
{
"title": "Forest mushroom",
"vendor": "Clover's Apothecary"
},
{
"title": "Gift Card",
"vendor": "Polina's Potent Potions"
},
{
"title": "Glacier ice",
"vendor": "Ted's Apothecary Supply"
},
{
"title": "Ground mandrake root",
"vendor": "Clover's Apothecary"
},
{
"title": "Health potion",
"vendor": "Polina's Potent Potions"
},
{
"title": "Invisibility potion",
"vendor": "Polina's Potent Potions"
},
{
"title": "Komodo dragon scale",
"vendor": "Ted's Apothecary Supply"
},
{
"title": "Love Potion",
"vendor": "Polina's Potent Potions"
},
{
"title": "Mana potion",
"vendor": "Polina's Potent Potions"
},
{
"title": "Potion beats",
"vendor": "Polina's Potent Potions"
},
{
"title": "Potion bottle",
"vendor": "Polina's Potent Potions"
},
{
"title": "Viper venom",
"vendor": "Ted's Apothecary Supply"
},
{
"title": "Whole bloodroot",
"vendor": "Clover's Apothecary"
}
]
}
}Output
Blue Mountain Flower
Output
Blue Mountain FlowerAnchor to Returns `nil` when no items match the specified property value.
Returns nil when no items match the specified property value.
nil when no items match the specified property value.{% assign product = collection.products | find: 'vendor', "Polina's Potions" %}
{{ product.title | default: "No product found" }}
Code
{% assign product = collection.products | find: 'vendor', "Polina's Potions" %}
{{ product.title | default: "No product found" }}Data
{
"collection": {
"products": [
{
"id": 6789374705729,
"vendor": "Polina's Potent Potions"
},
{
"id": 6790277595201,
"vendor": "Ted's Apothecary Supply"
},
{
"id": 6792602320961,
"vendor": "Polina's Potent Potions"
},
{
"id": 6792607825985,
"vendor": "Clover's Apothecary"
},
{
"id": 6816899596353,
"vendor": "Polina's Potent Potions"
},
{
"id": 6790315212865,
"vendor": "Clover's Apothecary"
},
{
"id": 6792635580481,
"vendor": "Clover's Apothecary"
},
{
"id": 6823781007425,
"vendor": "Polina's Potent Potions"
},
{
"id": 6792632795201,
"vendor": "Ted's Apothecary Supply"
},
{
"id": 6792575352897,
"vendor": "Clover's Apothecary"
},
{
"id": 6786188247105,
"vendor": "Polina's Potent Potions"
},
{
"id": 6786989391937,
"vendor": "Polina's Potent Potions"
},
{
"id": 6792613462081,
"vendor": "Ted's Apothecary Supply"
},
{
"id": 6784387022913,
"vendor": "Polina's Potent Potions"
},
{
"id": 7067094777921,
"vendor": "Polina's Potent Potions"
},
{
"id": 6817196572737,
"vendor": "Polina's Potent Potions"
},
{
"id": 6821963563073,
"vendor": "Polina's Potent Potions"
},
{
"id": 6790469058625,
"vendor": "Ted's Apothecary Supply"
},
{
"id": 6792596455489,
"vendor": "Clover's Apothecary"
}
]
}
}Output
No product found
Output
No product foundWas this page helpful?