Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Array Type Extensions

Provides extensions to the base ECMAScript (JavaScript) Array Object functionality by adding static methods.

Namespace: None. This type extension is global and not part of a namespace.

Inherits: Array Object

Syntax

var arrayVar = new Array("Saturn","Mars","Jupiter");
Array.add(arrayVar, "Earth");

Member Extensions

Name

Description

add Function

Adds an element to the end of an Array object.

addRange Function

Copies all the elements of the specified array to the end of an Array object.

clear Function

Removes all elements from an Array object.

clone Function

Creates a shallow copy of an Array object.

contains Function

Determines whether an element is in an Array object.

dequeue Function

Removes the first element from an Array object.

enqueue Function

Adds an element to the end of an Array object.

note

Use the add function instead of the Array.enqueue function.

forEach Function

Performs a specified action on each element of an Array object.

indexOf Function

Searches for the specified element of an Array object and returns its index.

insert Function

Inserts a value at the specified location in an Array object.

parse Function

Creates an Array object from a string representation.

remove Function

Removes the first occurrence of an element in an Array object.

removeAt Function

Removes an element at the specified location in an Array object.

Remarks

Array extensions are part of the Microsoft AJAX Library. They add static methods to the JavaScript Array object for additional functionality.

For more information about the JavaScript object that these static methods extend and about its constructor, see Array Object in the JScript Language Reference.

Example

The following example shows how to create a new Array object and invoke the Microsoft AJAX Library add function to add arrays as an element to a single array. The multidimensional array is then passed to a function that displays the array as a table in the document.

JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>

        <div id="results">
        </div>

        <script type="text/javascript">

        // Create and display a table based on array content.
        function displayTable(arrayTable, element) 
        {
            var tableMarkup;
            tableMarkup = "<table border=on>";
            var rows = arrayTable[0][0].length;

            for(x=0; x<=rows; x++)
            {
               tableMarkup += "<tr>";
               var columns = arrayTable[x].length - 1;
               for(y=0; y<=columns; y++)
               {
                    tableMarkup += "<td>" + arrayTable[x][y] + "</td>";
               }
               tableMarkup += "/<tr>";
            }
            tableMarkup += "</table>";

            element.innerHTML += tableMarkup;

            // Clean up.
            Array.clear(arrayTable);
        }

        // Create table data.
        function createTableData() 
        {
               var costsArray = [];

               var headerRow = new Array("ID", "Name", "Costs");
               var firstRow = new Array("1", "ruler", "1.30");
               var secondRow = new Array("2", "binder", "4.75");

               Array.add(costsArray, headerRow);
               Array.add(costsArray, firstRow);
               Array.add(costsArray, secondRow);

               return costsArray;
        }  

        var myTable = createTableData();
        var element = $get("results");
        displayTable(myTable, element);

    </script>
    </form>
</body>
</html>