Click to See Complete Forum and Search --> : What's the JS equivalent to this...


mitya
10-28-2003, 10:50 AM
Hi all

In PHP, if I want to break apart a string and handle different parts of it individually, I'd use explode(), so the following would return an array with three keys, each holding '0'.

$string = "0---0---0";
$array = explode("---", $string);

Can anyone tell me if this can be done in JS?

gil davis
10-28-2003, 11:36 AM
var st1 = "0---0---0";
var st2 = st1.split("---");

mitya
10-28-2003, 11:38 AM
And would that return an array, or just a string with the first 0 in? Ideally I need an array with three keys in.

Someone suggested:

var my_array = new array(string.split("---"));

...but all that seems to do is commit the entire string, minus the '---' to the first array key, rather than put one zero in each key.

Thanks for the help.

gil davis
10-28-2003, 11:56 AM
would that return an arrayYes.

mitya
10-28-2003, 12:22 PM
Thanks for that, that's great.