Prototype - first() 方法



此方法返回陣列中的第一個元素,或如果陣列為空,則返回 undefined。

語法

array.first();

返回值

返回陣列的第一個元素。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var arr = ['Sam', 'Justin', 'Andrew', 'Dan'];
            alert("First element is : "  + arr.first() );
         }
      </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.