arrayInsertAt

Inserts a value at the specified position in the array. If the element is inserted before the end of the array, ColdFusion shifts the positions of all elements with a higher index to make room.

arrayInsertAt(array, position, value) → returns boolean

Member Function Syntax

someArray.insertAt(position, value)

arrayInsertAt Argument Reference

array array
Required

The array which will have the new element inserted.

position numeric
Required

The numerical index in the array where the new element will be inserted.
Must be less than or equal to the length of the array.
Remember ColdFusion arrays start at 1 not 0.

value any
Required

The new element to insert.

Examples sample code invoking the arrayInsertAt function

Inserts the number 4 at position 2

someArray = [1,2,3];
arrayInsertAt(someArray, 2, 4);
writeOutput(serializeJSON(someArray));

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


Fork me on GitHub