Prototype - Enumerable size() Method


Advertisements


This method returns the size of the enumeration.

Syntax

Iterator.size();

Return Value

Returns the size of the enumeration.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var arr = $R(1, 10).select(function(n) { return 0 == n % 2; });

            alert("Test 1 : " + $R(1, 10).size() );
            // Returns 10

            alert("Test 2 : " + ['hello', 42, true].size() );
            // Returns 3

            alert("Test 3 : " + $H().size() );
            // Returns 0
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

Output


prototype_enumerating.htm

Advertisements