Replace javascript does not work in general

Asked

Viewed 746 times

1

Why when I do:

"1.000.000,00".replace('.','');

he returns me:

"1000.000,00"

How do I make it work with all characters? that would be so: "1000000,00"

  • 2

    Why the three votes to reopen? Even after editing, the solution is the same (use a regular expression with the 'global' flag). Remember that closing as a duplicate is not a bad thing. In most cases, it is good to keep multiple questions on the same subject, but pointing to the same answer. This increases the chance of finding the answer via search engines.

1 answer

2


Make a replace global with the option, change your replace, for:

"SILVANO SILVADO".replace(/A/g,'@');

Demo: Jsfiddle

Edited

After editing the question, follow the new solution:

"1.000.000,00".replace(/\./g,'')

Demo: Jsfiddle

  • Cool, I know I didn’t ask the question, but what if it is 1.000.000,00 ? I can do this "1.000.000,00".replace(/./g,''); ? to remove all points?

  • Yes, you can use an scape "1.000.000,00".replace(/\./g,''), see http://jsfiddle.net/R2nnK/1/

  • Friend due to complications I edited the question, could you please post that comment solution as answer?

  • 1

    @Silvioandorinha, feito

Browser other questions tagged

You are not signed in. Login or sign up in order to post.