> For the complete documentation index, see [llms.txt](https://docs.plumvoice.com/dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.plumvoice.com/dev/voicexml/tags/foreach-tag.md).

# \<foreach>

## \<foreach> <a href="#foreach" id="foreach"></a>

The `<foreach>` element allows a VoiceXML application to iterate through an ECMAScript array and to execute the content contained within the `<foreach>` element for each item in the array.

### Attributes

<table><thead><tr><th width="165.33333333333331">Name</th><th width="145">Data type<select><option value="e34e5ffcdba4485da7321672d597a4b8" label="String" color="blue"></option><option value="1bf311113b52477bbf49042da8980b32" label="Integer" color="blue"></option><option value="8eb5a21a18f74ceb8a508ba48479c69f" label="Boolean" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>array</td><td><span data-option="e34e5ffcdba4485da7321672d597a4b8">String</span></td><td>An ECMAScript expression that must evaluate to an array; otherwise, an error.semantic event is thrown.</td></tr><tr><td>item</td><td><span data-option="e34e5ffcdba4485da7321672d597a4b8">String</span></td><td>The variable that stores each array item upon each iteration of the loop. A new variable will be declared if it is not already defined within the parent's scope.</td></tr></tbody></table>

### Notes

Both “array” and “item” must be specified. Please refer to the [VoiceXML 2.1 Draft](http://www.w3.org/TR/2004/WD-voicexml21-20040728/) for examples and detailed usage information for this tag.

### Example

```markup
<?xml version="1.0"?>
<vxml version="2.1">
  <form>
    <script>
      var movies = new Array();
      movies[0] = new Object();
      movies[0].audio = 'godfather.wav';
      movies[0].tts = 'The Godfather';
      movies[1] = new Object();
      movies[1].audio = 'highfidelity.wav';
      movies[1].tts = 'High Fidelity';
      movies[2] = new Object();
      movies[2].audio = 'raiders.wav';
      movies[2].tts = 'Raiders of The Lost Ark';
    </script>
    <field name="mov">
      <prompt>
        Please select one of the following movies.
        <break time="500ms"/>
        <foreach item="movie" array="movies">
          <audio expr="movie.audio"><value expr="movie.tts"/></audio>
          <break time="500ms"/>
        </foreach>
      </prompt>
      <grammar mode="voice" type="application/srgs+xml" root="ROOT">
        <rule id="ROOT">
          <one-of>
            <item>The Godfather</item>
            <item>High Fidelity</item>
            <item>Raiders of The Lost Ark</item>
          </one-of>
        </rule>
      </grammar>
      <filled>
        You said <value expr="mov"/>.
      </filled>
    </field>
  </form>
</vxml>
```

The output of the above script would be:

> Computer: Please select one of the following movies.\
> Computer: The Godfather, High Fidelity, Raiders of The Lost Ark.\
> Human: High Fidelity.\
> Computer: You said High Fidelity.

### Child Tags

[\<audio>](/dev/voicexml/tags/audio-tag.md), [\<assign>](/dev/voicexml/tags/assign-tag.md), [\<break>](/dev/voicexml/tags/break-tag.md), [\<clear>](/dev/voicexml/tags/clear-tag.md), [\<data>](/dev/voicexml/tags/data-tag.md), [\<disconnect>](/dev/voicexml/tags/disconnect-tag.md), [\<emphasis>](/dev/voicexml/tags/emphasis-tag.md), [\<enumerate>](/dev/voicexml/tags/enumerate-tag.md), [\<exit>](/dev/voicexml/tags/exit-tag.md), [\<foreach>](/dev/voicexml/tags/foreach-tag.md), [\<goto>](/dev/voicexml/tags/goto-tag.md), [\<if>](/dev/voicexml/tags/if-tag.md), [\<log>](/dev/voicexml/tags/log-tag.md), [\<metadata>](/dev/voicexml/tags/metadata-tag.md), [\<mark>](/dev/voicexml/tags/mark-tag.md), [\<paragraph>](/dev/voicexml/tags/paragraph-tag.md), [\<phoneme>](/dev/voicexml/tags/phoneme-tag.md), [\<prompt>](/dev/voicexml/tags/prompt-tag.md), [\<prosody>](/dev/voicexml/tags/prosody-tag.md), [\<reprompt>](/dev/voicexml/tags/reprompt-tag.md), [\<return>](/dev/voicexml/tags/return-tag.md), [\<say-as>](/dev/voicexml/tags/say-as-tag.md), [\<sentence>](/dev/voicexml/tags/sentence-tag.md), [\<script>](/dev/voicexml/tags/script-tag.md), [\<speak>](/dev/voicexml/tags/speak-tag.md), [\<sub>](/dev/voicexml/tags/sub-tag.md), [\<submit>](/dev/voicexml/tags/submit-tag.md), [\<throw>](/dev/voicexml/tags/throw-tag.md), [\<value>](/dev/voicexml/tags/value-tag.md), [\<var>](/dev/voicexml/tags/var-tag.md), [\<voice>](/dev/voicexml/tags/voice-tag.md)

### Parent Tags

[\<block>](/dev/voicexml/tags/block-tag.md), [\<catch>](/dev/voicexml/tags/catch-tag.md), [\<error>](/dev/voicexml/tags/error-tag.md), [\<filled>](/dev/voicexml/tags/filled-tag.md), [\<foreach>](/dev/voicexml/tags/foreach-tag.md), [\<help>](/dev/voicexml/tags/help-tag.md), [\<if>](/dev/voicexml/tags/if-tag.md), [\<noinput>](/dev/voicexml/tags/noinput-tag.md), [\<nomatch>](/dev/voicexml/tags/nomatch-tag.md), [\<prompt>](/dev/voicexml/tags/prompt-tag.md)
