developer_guide:voicexml_references:elements:foreach

< foreach >

Iterates through an ECMAScript array of items. New in VoiceXML 2.1.

<foreach
array = "ECMAScript_Expression"
item = "variable"
/>
arrayAn ECMAScript expression that evaluates to an array. Required.
itemThe variable that stores each array item upon each iteration of the loop. Required.
<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>, <prompt>
<assign>, <audio>, <break>, <clear>, <data>, <disconnect>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>
None.
None.
<?xml version="1.0"?>
<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
   <form id="play_fruit">
      <block>
         <!-- create an array of fruit names -->
         <var name="aFruit" expr="new Array('apples', 'oranges', 'pears', 'bananas')"/>

         Here's a list of fruit we have available today

         <!-- iterate throught through each item in the array -->
         <foreach item="fruit" array="aFruit">
            <value expr="fruit"/>
         </foreach>
      </block>
   </form>
</vxml>
  • developer_guide/voicexml_references/elements/foreach.txt
  • Last modified: 2015/10/27 12:36
  • by borja