This function adds one or more elements to the beginning of the original array and returns the length of the modified array.
arrayUnshift(array,object)
returns numeric
array.unshift(object)
Name | Type | Required | Default | Description |
---|---|---|---|---|
array | array | Yes | The original array to be added to. | |
object | any | Yes | The new object to be added. |
Add a new element to an array.
arr=[1,2,3];
newArrLen=arrayUnshift(arr,0);
writeOutput(newArrLen);
This is the same example as above, but using a member function on the array instead of a standalone function.
arr=[1,2,3];
newArrLen=arr.unshift(0);
writeOutput(newArrLen);