tracker issue : CF-4205052

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] Doc Bug for: sparse array loop handling is undocumented

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/Duplicate

Reporter/Name(from Bugbase): Aaron N. / ()

Created: 08/23/2019

Components: Documentation

Versions: 2018

Failure Type:

Found In Build/Fixed In Build: 2018.0.04.314546 /

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Windows 10 64 bit

Vote Count: 0

Issue: The docs for the various array looping constructs should link to a central doc which outlines how they handle sparse arrays.

Repro:

<cfset myArray = ["foo",javaCast("null","")]>
<cfset myArray[4] = "bar">

<!--- These loop 2 times --->
<cfset i = 0>
<cfloop array="#myArray#" index="myElement">
  <cfoutput>#++i#</cfoutput>
</cfloop>
<hr>
<cfscript>
  i = 0;
  cfloop(array=myArray, index="myElement") {
	  writeOutput(++i);
  }
  writeOutput("<hr>");
  i = 0;
  for(myElement in myArray) {
	  writeOutput(++i);
  }
  writeOutput("<hr>");
</cfscript>

<!--- These loop 4 times --->
<cfloop from="1" to="#myArray.len()#" index="i">
  <cfoutput>#i#</cfoutput>
</cfloop>
<hr>
<cfscript>
  cfloop(from=1, to=myArray.len(), index="i") {
	  writeOutput(i);
  }
  writeOutput("<hr>");
  myArray.each(function(myElement, myIndex, myArray) {
	  writeOutput(myIndex);
  });
  writeOutput("<hr>");
  myArray.map(function(myElement, myIndex, myArray) {
	  writeOutput(myIndex);
  });
  writeOutput("<hr>");
  myArray.filter(function(myElement, myIndex, myArray) {
	  writeOutput(myIndex);
	  return true;
  });
  writeOutput("<hr>");
  myArray.reduce(function(myResult, myElement, myIndex, myArray) {
	  writeOutput(myIndex);
  });
  writeOutput("<hr>");
</cfscript>

Related ticket: CF-3864256

Related URL: https://www.bennadel.com/blog/3531-coldfusion-2016-skips-over-undefined-elements-with-for-in-array-loop.htm

Attachments:

Comments:

Hi Adobe, I forgot to mention, the behavior is the same irrespective of if CF2018's null support is enabled or not. Also, regarding the constructs in the "These loop 4 times", please do not change their behavior. Thanks!, -Aaron
Comment by Aaron N.
31161 | August 23, 2019 09:51:40 AM GMT
Blocker: CF-4205055 Hi Adobe, Please do not implement yet. The fix for CF-4205055 would make this CF-4205052 ticket irrelevant. Thanks!, -Aaron
Comment by Aaron N.
31167 | August 24, 2019 12:01:11 AM GMT
closing this. It's not relevant is CF-4205055 is to be fixed.
Comment by Piyush K.
31761 | November 07, 2019 06:28:23 AM GMT