Thursday, 14 July 2016

JavaScript - Replace Comma with New Line

Use JavaScript String functions "split" and "join":
var formattedString = yourString.split(",").join("\n")
If you'd like the newlines to be HTML line breaks replace "\n" with "<br />"

Alternate method using "replace" function.
yourString.replace(/,/g, '\n');

No comments:

Post a Comment