How does JavaScript replace all
This article is about how JavaScript can replace everything. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
replace all
The String.replace() function allows you to replace strings with strings or regular expressions. The function itself only replaces *** occurrences of strings, but you can use the regular expression/g to simulate the function of replaceAll():
var string = "john john"; console.log(string.replace(/hn/, "ana")); // "joana john" console.log(string.replace(/hn/g, "ana")); // "joana joana" Thank you for reading! About "JavaScript how to replace all" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!