Trimming whitespace in JavascriptUnlike most programming languages, Javascript does not have a built-in method to allow trimming white space off of strings. If you want to perform trimming of white space in Javascript, here are some functions you can use to perform this functionality.
function trimString(inString) {
// Trims space from the left and right sides of the string
return inString.replace(/^\s+|\s+$/g, "");
}
function trimStringLeft(inString) {
// Trims space from the left side of a string
return inString.replace(/^\s+/g, "");
}
function trimStringRight(inString) {
// Trims space from the right side of a string
return inString.replace(/\s+$/g, "");
}
|

