-1

I'm sure you all know that "some string".replace("s", "") strips only first "s" occurence But what is the reason?

Can anyone give me some input on internal logic of this? I've failed to find out this at EMCA specs I mean that every decision should have a motivation part and it is really important for me to understand the reason.

josh3736
  • 139,160
  • 33
  • 216
  • 263
skyboyer
  • 22,209
  • 7
  • 57
  • 64
  • 1
    Why *should* it replace all occurrences? If you want it to do that, pass in a regular expression with the "g" flag set, [like it says in the documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Description). – Pointy Sep 25 '15 at 17:09
  • 3
    Ecma != W3C; that are two different standardization organizations… – feeela Sep 25 '15 at 17:09
  • If you want to know the motivation behind that behavior, Stack Overflow is not the right place to find an answer to that. Reach out to the people who actually work on the spec. – Felix Kling Sep 25 '15 at 17:48
  • sorry guys it's actually not "how-to-do-this" question. I'm really interested in "why". and I have no idea where is it possible to find out any discussions/mails/draft discussions. so it's more about "where _could_ I find such type of information?" – skyboyer Sep 25 '15 at 20:04

1 Answers1

5

The reason it works that way is right there in the spec:

If searchValue is not a regular expression, let searchString be ToString(searchValue) and search string for the first occurrence of searchString. Let m be 0.

The spec says look for the first occurrence, not each occurrence.

josh3736
  • 139,160
  • 33
  • 216
  • 263