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