Home > Web Front-end > JS Tutorial > JavaScript push usage guide_Basic knowledge

JavaScript push usage guide_Basic knowledge

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:28:54
Original
1718 people have browsed it

The

push() method adds one or more elements to the end of the array and returns the new length. The return value is the new length after adding the specified value to the array.
Syntax: arrayObject.push(newelement1,newelement2,....,newelementX)
Parameter newelement1, required. The first element to be added to the array.
Parameter newelement2, optional. The second element to be added to the array.
Parameter newelementX, optional. Multiple elements can be added.

The push() method adds its parameters sequentially to the end of arrayObject. It directly modifies the arrayObject instead of creating a new array. The push() method and pop() method use the first-in-last-pop function provided by the array. This method changes the length of the array.

Example:

Copy code The code is as follows:









<script><br>       var btn=document.getElementById('btn');<br>          btn.onclick=function(){<br>         var arrays=new Array();<br>         var checkitem=document.getElementsByName("check");<br> for(var i=0;i<checkitem.length;i )<br />             {<br /> If(checkitem[i].checked){<br />                     arrays.push(checkitem[i].value);//Pass the value in () into the arrays array <br />             }<br />          }<br /> alert(arrays.length)<br /> }<br /> </script>

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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template