Skip to main content

JavaScript replace all commas in a string ?

JavaScript replace function can be used to replace a part of string inside a string variable.

Take an example string - "one, two, three, four"
Using JavaScript replace function

var str= "one, two, three, four";
str= str.replace(',','');
- but this will replace only the first occurrence of "," which will give the result as 

"one two, three, four"

if you want to remove all occurrences of the string, following RegExp can be used.

var str= "one, two, three, four";str.replace(/,/g , "");
This will give output as "one two three four"


  1. Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
    Webdesining course in chennai

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai


  3. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    WordPress development company in Chennai

  4. Awesome blog! I'm glad that I came across your blog. This'll be of great help for newbies like me. I'm following your blogs and you're doing a great job. Regards.
    Javascript Training in Chennai | Javascript Course | Javascript Training Center in Chennai | Javascript Training Courses

  5. This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
    WordPress website development Chennai

  6. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on

    Guest posting sites

  7. I have read your blog its very attractive and impressive. I like it your blog.

    Article submission sites

  8. This comment has been removed by the author.


Post a Comment