Home > Web Front-end > JS Tutorial > body text

How to use push method

不言
Release: 2021-04-20 10:40:21
Original
12128 people have browsed it

The push method is to add the given element to the last element of the array and return the length of the new array. Its usage syntax is "array.push(element1, ..., elementN);".

How to use push method

The operating environment of this article: Windows 7 system, Dell G3 computer, javascript version 1.8.5.

The push() method of Javascript array adds the given element to the last element of the array and returns the length of the new array. Let’s take a look at the specific use of the push method.

Let’s first take a look at the basic syntax of the push() method

array.push(element1, ..., elementN);
Copy after login

element1,..., elementN represents the element to be added to the end of the array.

Next let’s look at the specific usage examples of the push method

The code is as follows

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></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>
Copy after login

The display effect on the browser is as follows:

How to use push method

This article ends here. For more exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !

The above is the detailed content of How to use push method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!