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