In this example we will use the Array Type static extension methods that get added to the base ECMAScript (JavaScript) Array when using the Microsoft AJAX Client Library.
To use the Microsoft AJAX Client Library you need to add a ScriptManager control within the Form tags of your WebForm.
var vehicleList = new Array("VW Golf", "Audi A5", "VW Jetta"); Array.add(vehicleList, "Audi A3"); Array.add(vehicleList, "VW Polo"); Array.add(vehicleList, "VW Touareg"); // clone the Array var clonedList = Array.clone(vehicleList); // add the cloned Array to the vehicleList Array Array.addRange(vehicleList, clonedList); // Find the item that matches "VW Polo" alert("Contains VW Polo: " + Array.contains(vehicleList, "VW Polo")); // Remove the first element from the Array Array.dequeue(vehicleList); // Add an element to the Array Array.enqueue(vehicleList, "VW Golf"); // Find the item index of "Audi A5" alert("Index of Audi A5: " + Array.indexOf(vehicleList, "Audi A5")); // Insert element "Audi A4" in position 4 Array.insert(vehicleList, 4, "Audi A4"); // Remove element "VW Golf" alert("Removed VW Golf: " + Array.remove(vehicleList, "VW Golf")); // Remove element at position 1 Array.removeAt(vehicleList, 1); // perform an alert for each item Array.forEach(vehicleList, alert, null); // remove all items Array.clear(vehicleList);
You can download the Using Global Namespace Array Type project here