Node.jsでのプログラミングにおいて、”replaceAll is not a function”エラーが起こった場合の原因と対応についてメモです。
Node.jsやJavaScript言語でreplaceAll()関数を使用した際に、エラーになることがあります。
解決法としてはシンプルで、replaceAll関数でなく代わりにreplace関数を使用することです。
"hoge hoge hoge".replaceAll(/ /g, '')
Uncaught TypeError: "hoge hoge hoge".replaceAll is not a function
"hoge hoge hoge".replace(/ /g, '')
'hogehogehoge'
There is no replaceAll in JavaScript
javascript – String.prototype.replaceAll() not working – Stack Overflow