• This is an example of using the following methods in array class.
    • Array.foreach ( Array.forEach(_arrayObject, method, context);
    • Array.deque (var _aray = Array.dequeue(array) ;
    • Array.enqueue ( Array.enqueue(array, item);
    • var myClone = Array.clone(array);

    

Step: 1 Create a website ( http://manas6/aspnet.35/mm.JavaScriptArray4/default.aspx )

Step: 2 Add codes

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true"%>

<!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>mm.JavaScriptArray4: dequeue, enqueue</title>
<style type="text/css">
body { background-color:Gray; color:White }
#div1 { width:400px; height:250px; background-color:#FEFDDE;
color:Navy; padding-left:10px;
}
#display
{
width:300px; height:200px; background-color:#FEEDDE; color:Navy;
padding-left: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button4" runat="server" Text="Page-Reload" onclick="Button4_Click" />
<asp:Button ID="Button5" runat="server" Text="Clear-Deck"
onclick="Button5_Click" BackColor="#0066FF" Font-Size="Medium"
ForeColor="#FFFF99" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate><asp:Panel ID="Panel1" runat="server" Width="431px">
Keep these buttons within a panel to enforce click <br />events in the embedded
script. <br />
<asp:Button ID="Button1" runat="server" Text="Array-foreach" />
<asp:Button ID="Button2" runat="server" Text="Array-dequeue" />
<asp:Button ID="Button3" runat="server" Text="Array-enqueue" />
<br />

</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div id="div1"> This will contain result: Must use Clear Deck button <br />to clear up the display, and use other
Buttons.<br />
<asp:Label ID="display" runat="server" Text="Label"></asp:Label>
</div>
<br />
</div>
<script type="text/javascript" >
$addHandler($get("Button1"), "click", start);
$addHandler($get("Button2"), "click", do_dequeue);
$addHandler($get("Button3"), "click", do_enqueue);
var _array = new Array();var result = "";
_array = Array("emp1@gmail.com", "emp2@gmail.com", "emp3@gmail.com", "emp4@gmail.com");
//("emp1@gmail.com', 'emp2@gmail.com', 'emp3@gmail.com', 'emp4@gmail.com");
_array[6] = "manager@gmail.com";

function process(element, index, array) {
// "this" is the context parameter, i.e. '|'.

result += "<br/>" + element + this + index + ',';

}
function start() {
clear();
//alert();
result = "";
Array.forEach(_array, process, '|');
$get("display").innerHTML += result;

}
function do_dequeue() {
// alert("Do_dequeue");
clear();
$get("display").innerHTML += "<br/>Using dequeue";
Array.dequeue(_array);
Array.forEach(_array, process, '|');
//start();
$get("display").innerHTML +=result; ;
}
function do_enqueue() {
$get("display").innerHTML = "";
clear();
Array.enqueue(_array, "new_emp@gmail.com");
Array.forEach(_array, process, '|');
$get("display").innerHTML += "<br/>--- do_enqueue :---<br/>"+ result; ;

}
function clear() {
result = "";
alert("clearing/reloading array ");
$get("display").innerHTML = "";
}
window.onload = function() {
_array; result;
// start();
}
</script>
</form>
</body>
</html>
 

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button4_Click(object sender, EventArgs e)
{
//
}
protected void Button5_Click(object sender, EventArgs e)
{

}
}
 

Step: 3 Runtime analysis

A) First time and after the Page Load event: Here array is already loaded in the memory.

b) Now Click on Array-ForEach

C) Test dequeue:  Now Click on Clear Deck, then Array-dequeue button (clead -deck and Page-Reload would reload the page) while the buttons within update panel would fire an event without reloading the web-page. The

D) Test Array.enqueue, again Click on Clear-Deck and then Array-Enque button