Is there some javascript function that can take a string already formatted as an array, and casts it as an array?
var some_string = "[1,2,3,4]";
var some_array = castAsArray(some_string);
some_array.length // Returns 4.
What you're looking for is JSON.parse(). It'll take any string that represents a valid JavaScript object in JSON (JavaScript Object Notation), and convert it to an object.
var some_string = "[1,2,3,4]";
var some_array = JSON.parse(some_string);
some_array.length // Returns 4.
Even eval will do the trick. Using eval, is not good practice but it is just a suggestion.
a="[1,2,3,4]"
b=eval(a)
Understand that using eval is always a bad idea (always means at most of the cases) and this is one excellent SO question and answers discussing this.
eval like this. Answers should provide good code, not "suggestions"eval. JSON.parse isn't "the actual way". It's one if a number of different ways. The best way to do it will depend on the overall circumstance.
var some_array = JSON.parse(some_string);. If the actual string isn't JSON data, then a different approach will be needed.