- Prototype Tutorial
- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
- Prototype Useful Resources
- Prototype - Quick Guide
- Prototype - Useful Resources
- Prototype - Discussion
Prototype - $A() Method
The $A() function converts the single argument it receives into an Array object.
One suggested use is to convert DOM NodeLists into regular arrays, which can be traversed more efficiently.
Syntax
$A(iterable)
Return Value
List of elements in the form of array.
Example
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function showOptions() { var NodeList = $('employees').getElementsByTagName('option'); var nodes = $A(NodeList); nodes.each(function(node) { alert(node.nodeName + ': ' + node.innerHTML); }); } </script> </head> <body> <select id = "employees" size = "10" > <option value = "5">Mohtashim, Mohd</option> <option value = "8">Debi, Patnaik</option> <option value = "1">Madisetti, Praveen</option> </select> <br /> <input type = "button" value = "Show the options" onclick = "showOptions();"/> </body> </html>
Output
prototype_utility_methods.htm
Advertisements