Share via


Array.clear Function

Removes all elements from an Array instance. This function is static and is invoked without creating an instance of the object.

Array.clear(array);

Arguments

Term

Definition

array

The array to clear.

Remarks

Use the clear function remove all elements from an Array instance. The resulting array's length property will be zero.

Example

The following example shows how remove all elements from an array by calling the clear function.


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

<html xmlns="https://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>


See Also

Reference

Array Object

Array Type Extensions

Other Resources

Language Reference