Whatever message this page gives is out now! Go check it out!
ArrayGetAt(Array array, Integer index)array.at(Integer index)| Parameter | Type | Description |
|---|---|---|
| array | Array (required) | The target array to access. |
| index | Integer (required) | 1-based positive index or negative index. Positive indices count from the start; negative indices count from the end. |
Invalid array index: 10. Array size is 4.).-1 returns the last element, -2 returns the second-to-last.array.at() is equivalent to ArrayGetAt().
<cfscript>
arr = ['apple','banana','cherry','date'];
writeOutput(ArrayGetAt(arr,1));
writeOutput(ArrayGetAt(arr,3));
</cfscript>
<cfscript>
arr = ['apple','banana','cherry','date'];
writeOutput(ArrayGetAt(arr,-1));
writeOutput(ArrayGetAt(arr,-2));
</cfscript>
<cfscript>
arr = ['apple','banana','cherry','date'];
writeOutput(arr.at(-1));
writeOutput(arr.at(1));
</cfscript>
<cfscript>
arr = ['apple','banana','cherry','date'];
try {
ArrayGetAt(arr,10);
} catch(any e) {
writeOutput(e.message);
}
</cfscript>
<cfscript>
a1 = ArrayNew(2);
a1[1][1] = "one-one";
a1[2][2] = "two-two";
writeOutput(ArrayGetAt(a1,1)[1]);
</cfscript>
<cfscript>
a3 = ArrayNew(3);
a3[1][1][1] = 100;
result = ArrayGetAt(ArrayGetAt(ArrayGetAt(a3,1),1),1);
writeOutput(result);
</cfscript>