How to insert an element at array specific position in ColdFusion

ArrayInsertAt() - insert array element at specific position

ArrayInsertAt.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ArrayInsertAt function example: how to insert array element at specific position</title>
</head>

<body>
<h2 style="color:hotpink">ArrayInsertAt Function Example</h2>

<cfset ColorArray = ArrayNew(1)>
<cfset Temp = ArrayAppend(ColorArray,"BurlyWood")>
<cfset Temp = ArrayAppend(ColorArray,"Chartreuse")>
<cfset Temp = ArrayAppend(ColorArray,"Chocolate")>
<cfdump var="#ColorArray#" label="Color Array">

<br />
<cfset Temp = ArrayInsertAt(ColorArray,2,"CadetBlue")>
<cfdump var="#ColorArray#" label="Color Array[After insert CadetBlue in position 2]">
</body>
</html>






More ColdFusion examples