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('_');

@JimmyP @rajug

both replies are Good . thanks !

hmm one problem … still


				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 …


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


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

@rajug this is jquery code.

ohh . its my mistake …


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.