ColdFusion 9 fixes arrayIsDefined

I coulda sworn I had blogged this earlier but it didn’t show up on my search. This just came up in a meeting at work so I thought I’d share. ColdFusion 8 added the arrayIsDefined function. As you can probably guess it let’s you check to see if an array has a value at a certain position. However, it had one pretty silly drawback. If your array was had a size of 10 and you checked position 11, you would get an error. Therefore to really check to see if a certain array position existed, you had to use this:

<!--- assume array is called arr and N is the position you want to check ---> <cfif arrayLen(arr) gte n and arrayIsDefined(arr, n)>

ColdFusion 9 though fixes this. So your code can just be:

<!--- assume array is called arr and N is the position you want to check ---> <cfif arrayIsDefined(arr, n)>

Oddly, the docs for arrayIsDefined still insist that you must stay within the bounds of the array. I'm filing a comment now.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments