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