0

Splitting a string into an array in JavaScript

JavaScript
var s = "one, two, three, four, five"
console.log(s.split(", ")); // ["one", "two", "three", "four", "five"]
RUN

Use the array method .join to go back to a string:

var s = "one, two, three, four, five"

console.log(s.split(", ")); // ["one", "two", "three", "four", "five"]

console.log(s.split(", ").join("--")); // "one--two--three--four--five"
RUN
add comment
Suggest a different solution or add another example