views:

105

answers:

2

I'm trying to get everything before/after a comma from a string

var test = 'hello,world';

Result:

   var one = 'hello';
   var two = 'world';

What would be a good way to this?

Thanks

+8  A: 
.split

Extra text because I need to write 15 characters for this submission to be approved.

-- edit

okay, more explicitly:

var k = "a,b".split(",");
alert(k[0]);
alert(k[1]);
Noon Silk
are you serious about the >15 char rule?!
Ryan Fernandes
Yep. (hilariously I can't even write 'yep' in reply to this).
Noon Silk
+2  A: 
var test = 'hello,world',
    words = test.split(',');


   var one = words[0]; // hello
   var two = words[1]; // world
CMS