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"


Comments

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

    ReplyDelete
  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

    ReplyDelete

  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete

Post a Comment