# Map

A `map` flow allows a block of code to be executed once for each item in a dictionary. Note that the order of iteration is not guaranteed given the nature of dictionaries. Loops can also contain more nested loops inside them.&#x20;

In order to iterate over just values or key, use appropriate transformers `.keys()` and `.values()` on the source dictionary.

{% hint style="info" %}
If you want to iterate over an array, use [`for`](/supernova-dsm/pulsar-language/flows/for.md) flow instead.
{% endhint %}

### Syntax

Basic syntax of `map` flow is as follows:

```swift
{[ map [statement] into [key] [value] ]}
    Body, optionally using {{ key }} and {{ value }}
{[/]}
```

With the following required attributes:

* `key` - the newly created property where the iterated key is stored
* `value` - the newly created property where iterated value is stored
* `statement` - statement to be evaluated to retrieve data for the iterator. Dictionary is expected otherwise an error is thrown

For example, a `map` flow be used to create lists, menus, and similar structures from sourced data. Let's assume we have a variable `attributes` defined that contains following data:

```javascript
{
    "attributes": {
        "Stamina": "10",
        "Agility": "20",
        "Intelligence": "9001"
    }
}
```

You can iterate on user data by defining new variables `attributeName`  and `attributeValue` where each key and value of the dictionary get stored in each iteration:

```markup
<h1>Player stats</h1>
<ul>
    {[ map attributes to attributeName attributeValue ]}
    <li>{{ attributeName }}: ({{ attributeValue }})</li>
    {[/]}
</ul>
```

With each iteration, data in both `attributeName` and `attributeValue` is different, resulting in the following output:

```markup
<h1>Player stats</h1>
<ul>
    <li>Stamina: 10</li>
    <li>Agility: 20</li>
    <li>Intelligence: 9001</li>
</ul>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://supernova-developers.gitbook.io/supernova-dsm/pulsar-language/flows/map.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
