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