javascriptandroidreact-nativereplaceall

Why is string.replaceAll() not a function on Android React Native?


I recently stumbled on this issue that, though ran well on iOS, could not run on Android, even though I use the same code base and run them in parallel.

Error log on react native 0.64.4

Note that (number + '') always returns a string, and this code runs on iOS.

Trying the regex with the global flag "g":

string.replace(/searchString/g, replaceString)

like some suggested StackOverFlow answers does not work either.

Can you guys guess the reasons and provide solutions?


Solution

  • Alternative way to do this with the split and join functions.

    string.split("searchString").join("replaceString");