# Getting "values" of a dict

**URL:** <https://discourse.gohugo.io/t/getting-values-of-a-dict/40398>\
**Category:** support\
**Created:** [September 6, 2022, 3:32pm UTC](https://discourse.gohugo.io/t/getting-values-of-a-dict/40398 "2022-09-06T15:32:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [September 6, 2022, 3:32pm UTC](https://discourse.gohugo.io/t/getting-values-of-a-dict/40398/1 "2022-09-06T15:32:54Z")

</div>

Assuming I have a `dict` that is created somehow dynamically and then sorted and processed, is there a way to get all `values` of the `dict` or will I always have to range though the dict to get the items in a slice?

Sample `dict`:

```nohighlight
{{ $something := dict
    "key1" "value1"
    "key2" "value2"
}}

```

sample result:

```nohighlight
{{ $values := "value1" "value2" }}

```

I know I could do a simple `range`, but is there a command to do this quickly?

```nohighlight
{{ $values := slice }}
{{ range $key, $value := $something }}
  {{ $values := $values | append $value }}
{{ end }}

```

The specific use case is a method that collects pages that are in several sections where each section has a different way to sort it’s pages.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 6, 2022, 4:10pm UTC](https://discourse.gohugo.io/t/getting-values-of-a-dict/40398/2 "2022-09-06T16:10:56Z")

</div>

> [@davidsneighbour](#):
>
> will I always have to range though the dict to get the items in a slice

Currently, yes.

In the future, possibly not.  
See [https://discourse.gohugo.io/t/7891/74](https://discourse.gohugo.io/t/7891/74).

The Go [`maps.Keys`](https://pkg.go.dev/golang.org/x/exp/maps#Keys) and [`maps.Values`](https://pkg.go.dev/golang.org/x/exp/maps#Values) functions are still experimental. When they are no longer experimental, I think it would make sense to create matching template functions in Hugo.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 8, 2022, 4:10pm UTC](https://discourse.gohugo.io/t/getting-values-of-a-dict/40398/3 "2022-09-08T16:10:59Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
