ArrayPrepend
Append a value to the start an array
Method Signature
ArrayPrepend(array=[modifiableArray], value=[any])
Arguments
Argument
Type
Required
Description
Default
array
modifiableArray
true
The array to prepend to
value
any
true
The value to prepend
Examples
Prepend a value to an array
Uses the arrayPrepend function to prepend a value to the beginning of an array and shifts the positions of the existing elements.
someArray = [
3,
2,
1
];
arrayPrepend( someArray, 4 );
writeDump( someArray );
Result: [4,3,2,1]
Prepend a value to an array using the Array member function
Invoking the prepend function on an array is the same as running arrayPrepend.
doctorArray = [
"Eccleston",
"Tennant",
"Smith",
"Capaldi"
];
doctorArray.prepend( "Hurt" );
writeDump( doctorArray );
Result: ['Hurt','Eccleston','Tennant','Smith','Capaldi']
Additional Examples
someArray = [
3,
2,
1
];
arrayPrepend( someArray, 4 );
dump( someArray );
// member function
doctorWhoArray = [
"Whittaker",
"Tennant",
"Baker"
];
doctorWhoArray.prepend( "Hurt" );
dump( doctorWhoArray );
Related
Last updated
Was this helpful?