Whatever message this page gives is out now! Go check it out!
ArraySplice(array,index[,elementCountForRemoval,replacements])array.splice(index,elementCountForRemoval,replacements)Parameter | Required/Optional | Description |
array | Required | The array to splice and modify. |
index | Required | The position at which to start modifying the array. If the position is greater than the length of the array, the start is set to the length of the array. If the position is less than 0, the start is set to the beginning of the array and the origin is set accordingly. |
elementCountForRemoval | Optional | The number of elements to be removed starting with the start index. |
replacements | Optional | Array of elements to be added to the array starting with index start. |
<cfscript>
months = ['Jan', 'March', 'April', 'June']
item=["Feb"]
// Insert Feb at position 2 while removing 0 elements
ArraySplice(months,2, 0, item)
WriteDump(months)
</cfscript><cfscript>
months = ['Jan', 'March', 'April', 'June']
item=["Feb"]
// Insert at position 3 while removing 2 elements
ArraySplice(array=months,index=3, elementCountForRemoval=2, replacements=item)
WriteDump(months)
</cfscript><cfscript>
months = ['Jan', 'March', 'April', 'June']
item=["Feb"]
// Insert at position -3 while removing 0 elements
ArraySplice(months,-3, 1, item)
WriteDump(months)
</cfscript><cfscript>
months = ['Jan', 'March', 'April', 'June']
item=["Feb"]
// Insert at position 5, which is greater that the length of array
ArraySplice(months,5, 0, item)
WriteDump(months)
</cfscript><cfscript>
months = ['Jan', 'March', 'April', 'June']
item=["Feb"]
// Insert at position 3 while removing 2 elements
months.Splice(3, 2, item)
WriteDump(months)
</cfscript>