Javascript Equivalent of PHP’s explode() and implode()

Do you know javascript has equivalent functions as php’s explode() and implode().

Let’s say we have a string:

$string = 'aa:bb:cc';

We want to break down each number into an array called $num_array.
In PHP we could do this:

$explode_array = explode(':', $string);

The PHP implode function would produce the following:

$explode_array[0] = 13
$explode_array[1] = 42
$explode_array[2] = 43
$explode_array[3] = 56

In Javascript, we can use split function.

var myArray = 'aa:bb:cc'.split(':'); 

Then let’s say we wanted to piece it back into the original string. We could just do this in php:

$string = implode(‘:’,$explode_array);

In Javascript, we can use join function.

myarray.join(':')  
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Javascript Equivalent of PHP’s explode() and implode()”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>