arrayPrepend

Inserts an array element at the beginning of an array
and shifts the positions of the existing elements to
make room.

arrayPrepend(array, value) → returns boolean

Member Function Syntax

someArray.prepend(value)

Argument Reference for the arrayPrepend function

array

Required: Yes

value

Required: Yes

Examples sample code invoking the arrayPrepend function


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);

Expected Result: [4,3,2,1]


Prepend a value to an array using the Array member function

CF 11+ Lucee 4.5+ Invoking the the prepend function on an array is the same as running arrayPrepend.

doctorArray = ['Eccleston','Tennant','Smith','Capaldi'];
doctorArray.prepend('Hurt');
writeDump(doctorArray);

Expected Result: ['Hurt','Eccleston','Tennant','Smith','Capaldi']


Fork me on GitHub