how to remove a comma from the end of the string in javascript code example Example: remove last comma from string javascript str = str.replace(/,\s*$/, "");