Tips & Tutorials – Javascript

How To Replace Characters In A String In Javascript – Simple Examples

Welcome to a quick tutorial on how to replace characters in a string in Javascript. Need to check and replace certain characters in Javascript? There are actually a number of ways to do it: var replaced = STRING.replace(“FROM”, “TO”); var replaced = STRING.replaceAll(“FROM”, “TO”); var replaced = STRING.replace(/FROM/g, “TO”); var replaced = theString.split(“FROM”).join(“TO”); That covers …

How To Replace Characters In A String In Javascript – Simple Examples Read More »

4 Ways To Remove Line Breaks In Javascript

Welcome to a quick tutorial on how to remove line breaks in Javascript. Want to remove all line breaks and create a “flat string” in Javascript? There are actually a few ways to do it: STRING.replace(/\r?\n|\r/, “”); STRING.replaceAll(“\r”, “”).replaceAll(“\n”, “”); To remove HTML line breaks – STRING.replaceAll(“<br>”, “”).replaceAll(“<br/>”, “”); To remove only leading and trailing …

4 Ways To Remove Line Breaks In Javascript Read More »