http://coldfusion.com logo
#cfml-general
Title
# cfml-general
r

raymondcamden

05/03/2022, 1:24 PM
Most recent ACF supports .each on arrays, right?
s

sknowlton

05/03/2022, 1:24 PM
Yes. For a while I think
since acf 2016
r

raymondcamden

05/03/2022, 1:26 PM
hmmm, ok going to share something
isArray returns true on kvp
if i change kvp to ["a","b"] it works
b

bdw429s

05/03/2022, 1:32 PM
Isn't split a java method
m

Myka Forrest

05/03/2022, 1:32 PM
That's what I'm wondering. What if you use
listToArray()
instead?
πŸ‘† 1
b

bdw429s

05/03/2022, 1:32 PM
It probably returns a native java array which won't have CFML member functions
βœ… 1
Use listtoarray
r

raymondcamden

05/03/2022, 1:32 PM
thats.... dumb
b

bdw429s

05/03/2022, 1:32 PM
That will give you a proper CF array
r

raymondcamden

05/03/2022, 1:33 PM
i guess i need to look up how to file a bug nowadays then
thanks
b

bdw429s

05/03/2022, 1:33 PM
It's a "feature", not a "bug" πŸ˜’
a

Adam Cameron

05/03/2022, 1:34 PM
It's not a bug.
You can't expect to call a method of the adobe.coldfusion.whatevs.Array class on an object of type java.lang.Array. That's just fundamental OOP.
r

raymondcamden

05/03/2022, 1:36 PM
so given that split on a string is expected to return an array, and given that isArray returns true, each should not work on the result because... ?
I thought each was sugar for the CF array method - not a Java method
a

Adam Cameron

05/03/2022, 1:37 PM
isArray
is being unhelpful here. It means "can this be passed to array functions", not "it's an actual CF array"
b

bdw429s

05/03/2022, 1:38 PM
The issue is, unlike headless functions like arrayEach() which cast the I'm incoming value to a CF array, the mrmber functions actually have to be defined on the object on question
βœ… 2
a

Adam Cameron

05/03/2022, 1:38 PM
arrayEach
would have worked here. Cos it takes loosely-typed "array"
but when you call a method on an object then it needs to be one of the methods that object's class actually implements.
r

raymondcamden

05/03/2022, 1:39 PM
right - again - i was assuming .each was sugar for CF's values, not Java
arrayEach - should that work in ACF?
a

Adam Cameron

05/03/2022, 1:41 PM
as in
arrayEach(myThingCfCanConventToACfmlArray, callback)
yes. Not as in
possNotACfmlArray.arrayEach(callback)
im fine with each working - but now curious πŸ˜‰
a

Adam Cameron

05/03/2022, 1:42 PM
right - again - i was assuming .each was sugar for CF's values, not Java
Well this is the thing. Your array - from a
String.split
call returns a java.lang.Array, not a CFML array.
.split
is not a CFML method; it's a
java.lang.String
method. You can't expect it to return a CFML array πŸ˜‰
m

Myka Forrest

05/03/2022, 1:43 PM
the syntax for arrayEach is slightly different. you need
arrayeach(a, function(){...})
r

raymondcamden

05/03/2022, 1:45 PM
Adam - yep! my fault for living in JS land for so long
myka - so is "each" Java? I'm trying to help someone here and want to KISS, if arrayEach is the CF sugar id rather show em that
m

Myka Forrest

05/03/2022, 1:46 PM
I'm not actually sure about that; I don't typically get into Java methods.
b

bdw429s

05/03/2022, 1:47 PM
No, it's CFML. Β Where you went wrong was calling split() which is a native java method and then expecting CF's member functions to work
πŸ‘ 2
Keep it all CFML (listtoarray()) and you'll be good
r

raymondcamden

05/03/2022, 1:47 PM
nod - completely forgot about listToArray
thanks all
b

bdw429s

05/03/2022, 1:48 PM
Also, don't forget about the ()=>{} sytax for your closures πŸ˜€
makes me happy to see fat arrow in CF
πŸ‘ 2
4 Views