[JavaScript] Remove Leading and Trailing Whitespaces


This post is a brief summary of links in the references.

Remove (Trim) Leading Whitespace (similar to Python lstrip)

function lstrip(str) {
  return str.replace(/^\s+/g, "");
}

Remove (Trim) Trailing Whitespace (similar to Python rstrip)

function rstrip(str) {
  return str.replace(/\s+$/g, "");
}