Are ArrayMap(), .map(), .filter(), and .reduce() only available in CFSCRIPT? In all my Google searching, I've never seen any examples in CF tags, only CFSCRIPT code.
^ _ ^
I would REALLY be surprised if that's the case. But the way you're going to use most of those functions is most likely to be in CFSCRIPT, because it's a "JS-like" way to do stuff. And I don't know if you could embed an unnamed callback function in CFML the way you can in CFSCRIPT.
Dave Watts, Eidolon LLC
Apparently that is what I'm finding out. Even using CFSET, I'm getting no love in my attempts to CFTAG it.
Which is no big deal. As you have pointed out, the most likely way these would be used would be inside CFSCRIPT tags, anyway. I was just throwing stuff against the wall to see what would stick.
Thank you for your response.
^ _ ^
Not so fast, fellers. 🙂 You can indeed use those functions in tags.
And while it’s true that an *unnamed* callback function won’t work in tags (I don’t think), I can say with confidence that a named one will—and that can be defined in cffunction (or script), then used in such functions.
I show an example of doing an arraymap in both script and tags, running at cffiddle here.
But to save you having to go there, and in case it may be better searched/found by folks in the future, here are the two variants.
The first is in fact code you wrote and offered, Wolf (here: https://coldfusion.adobe.com/2017/10/map-reduce-and-filter-functions-in-coldfusion/)
writeOutput("Animal number " & index & " is a " & item & "<br />");
And here it is in all its “tag glory”:
<cfoutput>Animal number #index# is a #item# <br /></cfoutput>
And please, no comments from the tag-hating peanut gallery. That’s really not the point of this thread.
Never thought I'd see the day I say "Thank you for proving my assertion wrong." LOL!
^ _ ^
Glad I could help.