JavaScript doesn't have a built-in replaceAll method to replace all occurrences of a string. It is recommended to use regular expressions to replace all occurrences of a string. A quick hack to replace all occurrence of a string in JavaScript without using regex is to use split and join method.
For example:
'hello, world'.split('world').join('john');
Will output:
"hello, john"
Comments
Add comment