Answer the question
In order to leave comments, you need to log in
javascript replace all
Sometimes in the source code of some libraries written by literate people, there is a construction string.split(find).join(replaceWith);
How is this better than the usual replace?
Answer the question
In order to leave comments, you need to log in
As written here , it works faster through split / join than through regular expressions in replace
As I remember, replace replaces only the first one found, while split-join replaces everything. Although I could be wrong.
The reason is not speed, but compatibility.
replace() is a non-standard function.
FF2.0 didn't support it.
Now it is already in all modern versions of browsers ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question