A brief talk on JavaScript push (), pop (), concat () method _javascript Skills

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]]])

Parameters
Arrayobj

Required option. An Array object.

Item, Item2,... itemn

Options available. The new element of the Array.

Description
The push method adds these elements in the order in which the new elements appear. If one of the arguments is an array, the array is added as a single element to the arrays. If you want to merge elements from two or more arrays, you need to use the Concat method.

Version requirements in: 5.5 Applied to: Array object

Pop method

Moves the last element in the divisor group and returns the element.

Arrayobj.pop ()

The required arrayobj reference is an Array object.

Description
If the array is empty, then the undefined is returned.

Concat Method (Array)

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

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

Parameters
Array1

Required option. The array object to which all other arrays are to be connected.

Item1,.. ., itemn

Options available. Other items to connect to the end of Array1.

Description
The Concat method returns an Array object that contains a connection to the 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, 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 an element from the source array to the result array:

• For object parameters that are copied from an array that is being connected to the new array, the same object is still pointed to after replication. Whatever changes in the new array and source array will cause another change.

• Copy only the value or string that is attached to the new array. A change in the value of an array does not affect the value in the other array.

Example

The following example illustrates the use of the Concat method when using an array:

function Concatarraydemo () {
  var A, B, C, D;
  A = new Array (1,2,3);
  b = "JScript";
  c = new Array ("VBScript");
  D = A.concat (b, c);
  Returns the array [1, 2, 3, JScript, N, "VBScript"] return
  (d);
}

The above article on the JavaScript push (), pop (), concat () method is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

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.