Wednesday, December 10, 2014

jQuery replace all spaces in a string

In jQuery to replace all occurrences of a space in a given string (and not just the first one), the following code will work.
var myString = "a simple string";
myString.replace(/ /g, '');
in this example the string will go from "a simple string" to "asimplestring".

No comments:

Post a Comment