Leron
Leron

Reputation: 9866

JavaScript - how to separate string by commas (just like PHP explode function)

I have a string containing values which are separated by commas within the string I want to get each value just like I would with PHP explode, but I need to do it in JavaScript. Is there a way and how can be done?

Thanks

Leron

Upvotes: 0

Views: 148

Answers (2)

Tschallacka
Tschallacka

Reputation: 28722

var mystring = "I like coffee, very much so, but I don't like...";
var exploded = mystring.split(",");
window.alert(exploded[1]);

Upvotes: 0

rfunduk
rfunduk

Reputation: 30442

How about:

"some,string,with,commas".split(',')

Upvotes: 6

Related Questions