The push () method adds one or more elements to the end of the array and returns a new length. The return value is the new length after the specified value is added to the array.
Syntax: Arrayobject.push (newelement1,newelement2,...., newelementx)
Parameter newelement1, required. The first element to add to the array.
Parameter newelement2, optional. The second element to add to the array.
Parameter newelementx, optional. Multiple elements can be added.
The push () method adds its parameter order to the tail of the arrayobject. Instead of creating a new array, it directly modifies the arrayobject. The push () method and the Pop () method use the advanced stack functionality provided by the array. This method changes the length of the array.
Example:
The
code is as follows:
<!doctype html>
<meta charset= "Utf-8" >
<body>
<input type= "checkbox" value= "1" name= "Check" checked= "Checked"/>
<input type= "checkbox" value= "1" name= "Check"/>
<input type= "checkbox" value= "1" name= "Check" checked= "Checked"/>
<input type= "checkbox" value= "1" name= "Check"/>
<input type= "button" value= "you selected number" id= "btn"/>
<script>
var Btn=document.getelementbyid (' btn ');
btn.onclick=function () {
var arrays=new Array ();
var checkitem=document.getelementsbyname ("Check");
for (var i=0;i<checkitem.length;i++)
{
if (checkitem[i].checked) {
Arrays.push (Checkitem[i].value);//The value inside is passed into the arrays array
}
}
alert (arrays.length)
}
</script>
</body>