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.

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.