Awee

pluck

Pluck extracts a single field from each element of a slice of maps and returns a slice of values.

Pluck extracts a single field from each element of a slice of maps and returns a slice of values.

Input

array

Parameters

#TypeRequired
0stringyes

Returns

array

Examples

Collect every user id

Input

users = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]

Template

{{ users | pluck:'id' }}

Output

[1, 2]

Gather product names

Input

products = [{"name": "Mug", "price": 12}, {"name": "Pen", "price": 3}]

Template

{{ products | pluck:'name' }}

Output

["Mug", "Pen"]

How is this guide?

On this page