Reputation: 4896
Something similar to the following JavaScript:
var a = "a,b,c".split(",");
Upvotes: 8
Views: 36756
Reputation: 32915
var a = ListToArray("a,b,c,d,e,f");
https://cfdocs.org/listtoarray
Upvotes: 29
Reputation: 3646
Your two main options are listToArray(myList) and the java method myList.split(), as noted in previous answers and comments. There are some things to note though.
For example:
listToArray("asdf,,,qwer,tyui") is ["asdf", "qwer", "tyui"]
listToArray("asdf,,,qwer,tyui", ",", true) is ["asdf", "", "", "qwer", "tyui"]
Re java split:
Like other java functionality that pokes up through the ColdFusion layer, this is undocumented and unsupported
In Adobe ColdFusion 8, 9, and 10, but not in Railo, this is a syntax error:
a = "asdf,,,qwer,tyui".split(",")
But this works:
s = "asdf,,,qwer,tyui";
a = s.split(",");
As far as I can see, Adobe ColdFusion treats the result of .split() like a ColdFusion array:
In Railo:
That's in contrast to real java arrays, created with createObject("java", "java.util.ArrayList").
NOTE: That's only partly correct; see edit below.
Edit: Thanks Leigh, I stand corrected, I should stick to what I know, which is CF way more than java.
I was reacting to the comment saying that the result of .split() "is not a ColdFusion array, but a native Java array. You won't be able to modify it via CF", which is not the case in my experience. My attempt to clarify that by being more specific was ill-informed and unnecessary.
Upvotes: 3