Array

The Array object allows you to create and manage arrays.

Syntax

The syntax for this object is:

new Array()
//Or
new Array(size)
//Or
new Array(argument1, argument2,...,argumentN)

Where:

size specifies the number of elements in the Array.

argument1,... specifies the list of arguments that are invoked with the constructor.

Sample

<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC "-//Nuance/DTD VoiceXML 2.0//EN"
"http://voicexml.nuance.com/dtd/nuancevoicexml-2-0.dtd" >
<vxml version="2.0">
...
   <script>
              var audArrIn = new Array("one", "two", "three");
       audArrIn.reverse(); // Needed to access array using pop()
   </script>
   <block name="foreacher">
            <var name="promptName" expr="audArrIn.pop()"/>
            <if cond="promptName != undefined">
                <prompt>
            <audio expr="promptName + '.wav'">
                                  Alternate TTS for <value expr="promptName"/>
                           </audio>
                </prompt>
                <clear namelist="foreacher"/>
          <else/>
                <prompt>Finished playing array</prompt>
          </if>
 </block>
...
</vxml>

Properties

This section describes the Array object properties.

constructor

The constructor property identifies the function used to create the Array object’s prototype.

The syntax for this property is:

array.constructor

length

The length property indicates the number of elements in the array.

The syntax for this property is:

array.length

prototype

The prototype property is used to add new methods and properties to the Array object.

The syntax for this property is:

Array.prototype.method
Array.prototype.property

Methods

This section describes the Array object methods.

concat()

The concat method allows you to concatenate arrays.

The syntax for this method is:

array.concat(argument1, ...)

join()

The join method allows you to concatenate the elements of an array into one string.

The syntax for this method is:

array.join()
//Or
array.join(string)

Where:

string is an optional argument that is used to separate the elements of the array in the returned string.

pop()

The pop method allows you to extract the last element from an array.

The syntax for this method is:

array.pop()

push()

The push method allows you to add elements to the end of an array.

The syntax for this method is:

array.push(argument1, ...)

Where:

argument1 identifies the first element to append to the end of the array.

reverse()

The reverse method allows you to reverse the order of the elements inside an array.

The syntax for this method is:

array.reverse()

shift()

The shift method allows you to delete elements at the beginning of an array.

The syntax for this method is:

array.shift()

slice()

The slice method returns a section of the array.

The syntax for this method is:

array.slice(start, stop)

Where:

start is the position in the array at which to start the slice.

stop is the position in the array at which to stop the slice.

sort()

The sort method allows you to sort the elements of an array.

The syntax for this method is:

array.sort()
//Or
array.sort(function)

Where:

function is a function used to specify the sorting order of the array.

splice()

The splice method allows you to insert and remove elements from an array.

The syntax for this method is:

array.splice(start, delete, argument2, ...)

Where:

start is the position in the array at which to begin the slice.

delete is the number of elements to remove from the array, beginning at the position specified by the start argument.

argument2, ... represents the list of elements to insert into the array, beginning at the position specified by the start argument.

toLocaleString()

The toLocaleString method allows you to convert an array to a localized strings.

The syntax for this method is:

array.toLocaleString()

toString()

The toString method allows you to convert an array to a string.

The syntax for this method is:

array.toString()

unshift()

The unshift method allows you to add elements to the beginning of an array.

The syntax for this method is:

array.unshift(argument1, ...)

Where:

argument1 identifies the first element to add to the array.

valueOf()

The valueOf method returns arrays as literal objects.

The syntax for this method is:

array.valueOf()