原型 - last() 方法



此方法返回陣列中的最後一個專案,如果陣列為空則返回 undefined。

語法

array.last();

返回值

返回陣列的最後一個元素。

範例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var arr = ['Apples', {good: 'yes', bad: 'no'}, 3, 34];
            alert("Last Element : "  + arr.last() );
         }
      </script>
   </head>

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

輸出

prototype_array_processing.htm
廣告
© . All rights reserved.