Home  >  Article  >  Web Front-end  >  How to use push method

How to use push method

不言
不言Original
2019-01-26 16:44:0912164browse

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

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>

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!

Statement:
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
Previous article:How to use split functionNext article:How to use split function