Array Type Extensions
Provides extensions to the base ECMAScript (JavaScript) Array functionality by adding static methods.
Namespace: None. This type extension is global and not part of a namespace.
Inherits: Array
var arrayVar = new Array("Saturn","Mars","Jupiter");
Array.add(arrayVar, "Earth");
Member Extensions
Name |
Description |
---|---|
Adds an element to the end of an Array object. |
|
Copies all the elements of the specified array to the end of an Array object. |
|
Removes all elements from an Array object. |
|
Creates a shallow copy of an Array object. |
|
Determines whether an element is in an Array object. |
|
Removes the first element from an Array object. |
|
Adds an element to the end of an Array object. Note Use the add function instead of the Array.enqueue function. |
|
Performs a specified action on each element of an Array object. |
|
Searches for the specified element of an Array object and returns its index. |
|
Inserts a value at the specified location in an Array object. |
|
Creates an Array object from a string representation. |
|
Removes the first occurrence of an element in an Array object. |
|
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 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.
<!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>