Awee

map

Map converts a slice of maps into a map keyed by the given field's string value.

Map converts a slice of maps into a map keyed by the given field's string value.

Input

array

Parameters

#TypeRequired
0stringyes

Returns

map

Examples

Index a list of users by id

Input

users = [{"id": "u1", "name": "Alice"}, {"id": "u2", "name": "Bob"}]

Template

{{ users | map:'id' }}

Output

{"u1": {"id": "u1", "name": "Alice"}, "u2": {"id": "u2", "name": "Bob"}}

Index categories by slug

Input

tags = [{"slug": "coffee", "label": "Coffee"}, {"slug": "tea", "label": "Tea"}]

Template

{{ tags | map:'slug' }}

Output

{"coffee": {"slug": "coffee", "label": "Coffee"}, "tea": {"slug": "tea", "label": "Tea"}}

How is this guide?

On this page