remove last character from string if comma javascript code example Example: remove last comma from string javascript str = str.replace(/,\s*$/, "");