Use .split
to go from strings to an array of the split substrings:
var s = "one, two, three, four, five"
s.split(", "); // ["one", "two", "three", "four", "five"]
Use the array method .join
to go back to a string:
s.split(", ").join("--"); // "one--two--three--four--five"