views:

280

answers:

3

I have a comma separated string that I want to convert into an array so I can loop through it.

Is there anything built-in to do this?

+8  A: 
var array = string.split(',');
Matchu
+1  A: 

The split() method is used to split a string into an array of substrings, and returns the new array.

var array = string.split(',');

Jakkwylde
A: 

In javascript and PHP you have these two very powerful functions:

JS: String.split(String) Array.join(String);

PHP: explode(string,string) implode(string,array)

Christian Sciberras
I like the note about `join`, but what is PHP doing in here?
Matchu
Thought I'd mention a valid counter part in a different language.
Christian Sciberras