Converting a text string to an array

An earlier routine has assembled a text string “string” with an unknown number of elements. I want to turn it into an array and then pop the final element. Therefore I use this code:

var string = "white,blue,red,green";
var myArray = new Array(string);
var lastelement = myArray.pop();
application.output(lastelement); // produces "white,blue,red,green" when I expected just "green".

What’s going on here? I’m misunderstanding the required syntax.

why do you expect that?
You are inserting a string that has comma’s yes but why should array do something with that?

It is just one string that gets one entry.

if you want to convert that string to an array look at the string.split() method

Thanks. Split() is exactly what I need in this situation. Thanks again.