JavaScript push, Pop, concat, join method

Source: Internet
Author: User

Push method

Adds a new element to an array and returns the new length value of the array.

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

Description

The push method adds these elements in the order in which the new elements appear (that is, append new elements to the end). If one of the parameters is an array, it is added as a single element to the array. If you are merging elements from two or more arrays, you need to use the concat method.

Version required in: 5.5 Applies to: Array Object

Pop method

Moves the last element in the array and returns the element.

arrayObj.pop( )

Description

If the array is empty, then the undefinedis returned.

Concat Method (Array)

Returns a new array, which is a combination of two or more arrays.

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

Description

The concat method returns an Array object that contains the connection for Array1 and any other items provided.

Items to add (item1 ... itemn) are added to the array in left-to-right order. If an item is an array, then add its contents to the end of the array1 . If the item is not an array, it is added to the end of the array as a single array element.

The following is a copy of the element from the source array to the result array:

    • For the object parameters copied from the array being connected to the new array, the same object is still pointed to after replication. Any change in the new array and the source array will cause another change.
    • For numeric values or strings connected to a new array, only its value is copied. Changing the value in one array does not affect the value in the other array.
Example

The following example illustrates the use of the concat method when using arrays:

function ConcatArrayDemo(){var a, b, c, d;   a = new Array(1,2,3);   b = "JScript";   c = new Array(42, "VBScript);a.concat(b, c);    Return array  [1, 2, 3, "JScript", 42, "VBScript"]    return(d); }
The join () method converts all the elements in the array into strings, and then joins them, which is exactly the opposite of the split () method of String. Join () defaults to use "," as a delimiter, and of course you can also specify delimiters in the method

JavaScript push, Pop, concat, join method

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.