Push (), pop (), concat () method, pushconcat

Source: Internet
Author: User

Push (), pop (), concat () method, pushconcat

Push method

Add the new element to an array and return 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.

Version 5.5 must be applied to: array objects.

Pop Method

Removes the last element from the array and returns the element.

ArrayObj. pop ()

The required arrayObj reference is an Array object.

Description
If this array is empty, undefined is returned.

Concat method (Array)

Returns a new array consisting of two or more arrays.

Array1.concat ([item1 [, item2 [,... [, itemN])

Parameters
Array1

Required. The Array object to be connected to all other arrays.

Item1,..., itemN

Optional. To connect to another project at the end of array1.

Description
The concat method returns an Array object that contains the connection between array1 and any other projects provided.

Project to be added (item1... ItemN) is added to the array from left to right. If an item is an array, add its content to the end of array1. If the project is not an array, add it as a single array element to the end of the array.

Copy elements from the source array to the result array as follows:

• For the object parameters copied from the array being connected to the new array, the Copied object still points to the same object. Any change in the new array and source array will lead to another change.

• For values or strings connected to the new array, only the values are copied. Changing the value of a group does not affect the value of another array.

Example

The following example illustrates the usage of the concat method when arrays are used:

Function ConcatArrayDemo () {var a, B, c, d; a = new Array (1, 2, 3); B = "JScript"; c = new Array (42, "VBScript); d =. concat (B, c); // returns an array [1, 2, 3, "JScript", 42, "VBScript"] return (d );}

The push (), pop (), and concat () methods in JavaScript are all shared by Alibaba Cloud. I hope you can give me a reference, we also hope that you can support the customer's home.

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.