Example Analysis of push function usage in javaScript

Source: Internet
Author: User

Example Analysis of push function usage in javaScript

This example describes how to use the push function in javaScript. Share it with you for your reference. The specific analysis is as follows:

The push method in javaScript adds new elements to an array and returns the new Length Value of the array.

ArrayObj. push ([item1 [item2 [... [itemN])

Parameters

ArrayObj, required. An Array object.

Item, item2,... itemN, optional. The new element of the Array.

Description

The push method adds new elements in the order they appear. If one of the parameters is an array, the array will be added to the array as a single element. To merge two or more elements in an array, use the concat method.

?

1

2

3

4

5

6

7

8

9

Array. prototype. push = function (){

Var len = arguments. length;

If (len> 0) for (var I = 0; I <len; I ++) this [this. length] = arguments [I];

Return this. length;

}

Var a = [1, 2, 4]

A. push (5)

Alert ()

Alert (a. push (6 ))

I hope this article will help you design javascript programs.

Note <>: For more exciting tutorials, please pay attention to the help house programming

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.