Most recent ACF supports .each on arrays, right?
# cfml-general
r
Most recent ACF supports .each on arrays, right?
s
Yes. For a while I think
since acf 2016
r
hmmm, ok going to share something
isArray returns true on kvp
if i change kvp to ["a","b"] it works
b
Isn't split a java method
m
That's what I'm wondering. What if you use
listToArray()
instead?
πŸ‘† 1
b
It probably returns a native java array which won't have CFML member functions
βœ… 1
Use listtoarray
r
thats.... dumb
b
That will give you a proper CF array
r
i guess i need to look up how to file a bug nowadays then
thanks
b
It's a "feature", not a "bug" πŸ˜’
a
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
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
isArray
is being unhelpful here. It means "can this be passed to array functions", not "it's an actual CF array"
b
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
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
right - again - i was assuming .each was sugar for CF's values, not Java
arrayEach - should that work in ACF?
a
as in
arrayEach(myThingCfCanConventToACfmlArray, callback)
yes. Not as in
possNotACfmlArray.arrayEach(callback)
im fine with each working - but now curious πŸ˜‰
a
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
the syntax for arrayEach is slightly different. you need
arrayeach(a, function(){...})
r
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
I'm not actually sure about that; I don't typically get into Java methods.
b
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
nod - completely forgot about listToArray
thanks all
b
Also, don't forget about the ()=>{} sytax for your closures πŸ˜€
makes me happy to see fat arrow in CF
πŸ‘ 2