Prototype-enum-size

提供:Dev Guides
移動先:案内検索

プロトタイプ-列挙可能なsize()メソッド

このメソッドは、列挙のサイズを返します。

構文

Iterator.size();

戻り値

列挙のサイズを返します。

<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>

出力