• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ArrayIsDefined

Explorer ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

Views

684

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

Since the index value of an element must be less than the length of the array this function ist worth nothing!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

I disagree. It can be that:

1) You are in a position in the code where you don't know the length of the array;

2)  You know the array's length is 3, for example, and you know the values of arr[1] and arr[3]. It is still possible that arr[2] doesn't exist.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

Sure, in this specific way it would work.

Well, the description says "True, if the array element is defined (exists)". So in my opinion it has to determine, if an index exists, no matter if the index is bigger than the length of the array. The isDefined function does the same. It checks the existance of an variable.

Let's say you loop through an array of users and several users are redundant. Now you would like to determine, if the next user is unequal to the current user. At the last index this funktion would through an error, which is pretty uncomfortable.

The only way to make this function work without errors, would be to check first the current index with the length of an array and after that to use the ArrayIsDefined Function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

The usage guidance is wrong: one can test beyond the length of the array, and has been able to do so since CF9.

http://adamcameroncoldfusion.blogspot.co.uk/2012/08/arrays-in-coldfusion-part-2.html#arrayIsDefined

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

LATEST

We are still using CF8, so I checked the behaviour in later versions and the description mentions the same. One more reason for us to upgrade.

Thanks for the information!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation