Discussion ForumHow to remove last comma from a string in javascript
vinod palne Staff asked 12 months ago
 

I have a string like this in JavaScript,

C#, ASP.NET, ASP.NET MVC, MS SQL,

I want to remove the last comma from the above string.

 

1 Answers
vinod palne Staff answered 12 months ago
 

This will remove last comma and any whitespace after it
var vLanguage=” C#,ASP.NET,ASP.NET.MVC,MS SQL,”;
var vFormattedValue=vLanguage.replace(/,\s*$/, “”);
console.log(vFormattedValue);