Miêu tả

Phương thức array push() trong Javascript thêm một hoặc nhiều phần tử tới phần cuối của một mảng và trả về độ dài mới của mảng.

Cú pháp

Cú pháp của nó như sau:

array.push(element1, ..., elementN);

Parameter Details

element1, ..., elementN: The elements to add to the end of the array.

Trả về giá trị

Trả về độ dài của mảng mới.

Ví dụ

Bạn thử ví dụ sau:

<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>

Kết quả

new numbers is : 1,4,9,10
new numbers is : 1,4,9,10,20 

Các bài học JavaScript khác tại s2sontech:




Bình luận (0)

Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Michael Gough
Learning English Everyday