Contact

If you like a new Web or Desktop
application, update a existing one
or add new modifications. Your at
the right place and hit the
hire me button

Follow

If your intersted you can follow
me on Twitter by clicking here

Web and Apps Building Refernce World Wild Web UNIX Apps AND Tips Programming languages

JavaScript equivalent of PHP explode function

In PHP we can easily break a long string into smaller parts by using the explode() function of PHP. In run rime, this function works like this:

$longstring=”Most of the time Amrit is confused — OK, not most of the time”;
$brokenstring=explode(” “, $longstring);

After the execution of the second command the variable $brokenstring is an array such that,

$brokenstring[0]=”Most”
$brokenstring[1]=”of”
$brokenstring[2]=”the”
$brokenstring[3]=”time”
$brokenstring[4]=”Amrit”
$brokenstring[5]=”is”
$brokenstring[6]=”confused”

and so on. So how do we do it in JavaScript. In JavaScript there is a split() function that achieves the same objective, although the syntax is a bit different.

var longstring=”Most of the time Amrit is confused — OK, not most of the time”;
var brokenstring=longstring.split(” “);

Now the variable brokenstring has all those words.