JavaScript的數組push()方法追加在最後該數組的給定元素(多個),並返回新的數組的長度。
語法
array.push(element1, ..., elementN);
下面是參數的詳細信息:
返回值:
返回新數組的長度。
例子:
<html> <head> <title>JavaScript Array push Method</title> </head> <body> <script type="text/javascript"> var numbers = new Array(1, 4, 9); var length = numbers.push(10); document.write("new numbers is : " + numbers ); length = numbers.push(20); document.write("<br />new numbers is : " + numbers ); </script> </body> </html>
這將產生以下結果:
new numbers is : 1,4,9,10 new numbers is : 1,4,9,10,20