A guide to using JavaScript for push

Source: Internet
Author: User
Tags arrays

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.