Prototype-array-reverse

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

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

このメソッドは、配列の逆バージョンを返します。 デフォルトでは、オリジナルを直接反転します。 inlineがfalseに設定されている場合、元の配列のクローンを使用します。

構文

array.reverse([inline = true]);

戻り値

配列の逆バージョンを返します。

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

      <script>
         function showResult() {
            var arr = [3, 5, 6, 1, 20];
            alert("Reversed Elements : "  + arr.reverse(true).inspect());
            alert("Reversed Elements : "  + arr.reverse(false).inspect());
         }
      </script>
   </head>

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

出力