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>单击按钮查看结果。</p> <br /> <br /> <input type = "button" value = "Result" onclick = "showResult();"/> </body> </html>
输出
prototype_array_processing.html