Not sure why I’m not able to create a new topic in the JavaScript FAQ section (but can create a topic in C#, Kotlin, Swift and Go FAQs), so it’ll have to go here.
On the Introduction to JavaScript tutorial, when trying to use .replaceAll()
to replace all instances of a character that matches a given pattern, a TypeError
is displayed:
/home/ccuser/workspace/learn-javascript-loops-P1/main.js:24
console.log(resultString.replaceAll(",",""));
^
TypeError: resultString.replaceAll is not a function
at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-loops-P1/main.js:24:26)
replace()
can be used to replace all instances with a regular expression as an argument. However, replaceAll() would be cleaner. According to the MDN docs, it is supported.