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 are 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 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( )
The required arrayobj Reference is an Array object.
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]]]])
Parameters
Array1
Required option. The array object to which all other arrays are to be connected.
Item1,.. ., itemn
Options are available. Other items to connect to the end of array1 .
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);
}
JavaScript push (), pop (), concat () method