TIL how to replace many characters in javascript
POSTED ON:
TAGS: mdn regex javascript
You can use the replace() method to swap one string pattern for another.
For example, to remove all the periods and replace them with dashes, you do this.
var result = str.replace(".", "-");
But what if you want to replace spaces, commas, and periods?
You can put it in a regex like this:
var result = str.replace(/[ ,.]/g, "");
Related TILs
Tagged: mdn