ArrayInsertAt()
Inserts a value at the specified position in the array. If the element is inserted before the end of the array, Lucee shifts the positions of all elements with a higher index to make room.
ArrayInsertAt( array=array, position=number, value=any );
Returns: Boolean
| Argument | Description |
|---|---|
|
array
array,
required
|
edit
The array which will have the new element inserted. |
|
position
number,
required
|
edit
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 CFML arrays start at 1 not 0. |
|
value
any,
required
|
edit
value to insert |
Examples
editInsert item into an array at a given position within the array length
fruitArray = ['apple', 'kiwi', 'banana', 'orange', 'mango', 'kiwi'];
arrayInsertAt(fruitArray,3,'new inserted item');
dump(fruitArray);
// member function
fruitArray.insertAt(3,'member added item');
dump(fruitArray);
See also
- Arrays
- array.insertAt()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)