# Using where() with maps and not arrays?

**URL:** <https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124>\
**Category:** support\
**Created:** [November 22, 2015, 8:09pm UTC](https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124 "2015-11-22T20:09:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m1keil](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@m1keil](https://discourse.gohugo.io/u/m1keil)\
**Post date:** [November 22, 2015, 8:09pm UTC](https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124/1 "2015-11-22T20:09:06Z")

</div>

Hi everyone,  
I wonder if there’s any possibility to use the `where` function on map data type and not lists/arrays?

For example, my data files structure is something like:

```auto
├── data
│ ├── events
│ │ ├── 2015chicago.yml
│ │ ├── 2015warsaw.yml
│ │ └── 2016kiel.yml

```

and each file looks like:

```auto
status = [past|current] # that's past or current

```

From the looks of it, I cannot run something like:  
`{{ range where $.Site.data.events "status" "past" }}` since `{{ range $.Site.data.events }}` is actually a map type (`map[filename][content]`).  
The only way I see to do what I want right now is to actually merge all these data files into one `event.yml` that contain an array instead of a dict.

Is there any other way to do what I want?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [November 22, 2015, 9:17pm UTC](https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124/2 "2015-11-22T21:17:42Z")

</div>

> [@m1keil](#):
>
> Is there any other way to do what I want?

@tatsushid would know, but I assume currently not possible. But it would be fairly easy to extend the `where` func with map support if we could agree on what to do about the sorting (as is (fairly random) or sort by key?)

---

<div class="post-metadata">

**Author:** ![m1keil](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@m1keil](https://discourse.gohugo.io/u/m1keil)\
**Post date:** [November 22, 2015, 9:38pm UTC](https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124/3 "2015-11-22T21:38:25Z")

</div>

Yea, I think going by key is the usual convention (since value can be complex data type).  
Python:

```auto
In [2]: x = [1,2,3]

In [3]: 1 in x
Out[3]: True

In [4]: y = {1:2,3:4}

In [5]: 1 in y
Out[5]: True

```

(`in` in Hugo doesn’t work with maps as well at the moment).  
Generally, I got the feeling that Hugo right now plays much better with arrays than maps. Maybe there’s a way to convert map into two different arrays? (first array is the keys, second is the values)

Thanks for your help.

_p.s_  
I just realized that if `where` were implemented to look by key in maps that doesn’t really help my case. But maybe other ideas might follow.

---

<div class="post-metadata">

**Author:** ![mattstratton](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mattstratton/32/24584_2.png) [@mattstratton](https://discourse.gohugo.io/u/mattstratton)\
**Post date:** [November 23, 2015, 4:54pm UTC](https://discourse.gohugo.io/t/using-where-with-maps-and-not-arrays/2124/4 "2015-11-23T16:54:29Z")

</div>

For color for anyone following at home, here’s how this is currently worked around (@m1keil and I are working on the same project together) :

```auto
        {{ range $.Site.Data.events }}
          {{ if eq .status "past" }}
            <li><a href = "/events/{{ .friendly }}/welcome">{{ .city }}</a></li>
          {{ end }}
        {{ end }}

```
