Awee

find

Find returns the first element in a slice or map where a field equals the given value.

Find returns the first element in a slice or map where a field equals the given value. Returns a non-fatal error when not found, allowing the default modifier to handle it.

Input

array map

Parameters

#TypeRequired
0stringyes
1anyyes

Returns

map

Examples

Look up a user by id

Input

users = [{"id": 7, "name": "Bob"}, {"id": 42, "name": "Alice"}]

Template

{{ users | find:'id',42 }}

Output

{"id": 42, "name": "Alice"}

Fall back when not found

Input

items = [{"slug": "hat", "price": 25}]

Template

{{ items | find:'slug','scarf' | default:{} }}

Output

{}

How is this guide?

On this page