ArrayUnshift
This function adds one or more elements to the beginning of the original array and returns the length of the modified array.
Method Signature
ArrayUnshift(array=[modifiablearray], object=[any])
Arguments
Argument
Type
Required
Description
Default
array
modifiablearray
true
The array to add an item to
object
any
true
The value to add
Examples
Example with simple values
Add a new element to an array.
arr = [
1,
2,
3
];
newArrLen = arrayUnshift( arr, 0 );
writeOutput( newArrLen );
Result: 4
Using a member function
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 );
Result: 4
Additional Examples
numbers = [
1,
2,
3,
4
];
Dump( ArrayUnShift( numbers, 0 ) ); // Outputs 5
moreNumbers = [
5,
6,
7,
8
];
Dump( ArrayUnShift( moreNumbers, 4 ) );
// Outputs 5
Related
Last updated
Was this helpful?