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