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