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: