Prototype-hash-each

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

プロトタイプ-each()メソッド

このメソッドは、ハッシュ内のキー/値のペアを反復処理するために使用されます。

構文

hash.each(iterator);

戻り値

キーと値のペアを返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            var h = $H({ version: 1.5, author: 'Sam Stephenson' });
            h.each(function(pair) {
               alert(pair.key + ' = "' + pair.value + '"');
            });
         }
      </script>
   </head>

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

出力