Php explode function alternative in jquery

hi . i have a value in variable like this price_33,product_1 . i want to explode like php function and store in array or two separate variables …

simple javascript or jquery solution ?


var str = 'price_33,product_1';
var exploded = str.split(',');

How about simply this split()?


var myvar = 'product_122';
var arr = myvar.split('_');
alert(arr[1]);

@JimmyP @rajug

both replies are Good . thanks !

hmm one problem … still

$copy_image_product_price_id=$($id).attr(“id”);

				var exploded = copy_image_product_price_id.split(',');
				var product_code=exploded[0];
				var product_price=exploded[1];

i m getting id and then split it but it not works …giving me error …

$copy_image_product_price_id=$($id).attr(“id”);

What does this line do actually? Is this PHP variable or jQuery’s one?


alert($('#mydivid').attr('id'));

This returns mydivid itself so i am confused what you are trying to do here.

@rajug this is jquery code.

ohh . its my mistake …

$copy_image_product_price_id=$($id).attr(“id”);

var exploded = copy_image_product_price_id.split(‘,’);

i had to use a variable sign with copy_image_product_price_id.split(‘,’); as
$copy_image_product_price_id.split(‘,’); …

its works now . thanks everybody.