The replace function can replace only one target string at a time, and can replace all strings in conjunction with the while loop.

1, define a string in the script tag, the string content is “a Chinese in north China is making Chinese knot”, and then output the content in the web page:

2. Use the replace function, where the first Chinese text is replaced with an empty string, but there are two Chinese text that are not replaced:

3. Add a while loop to determine if the word “China” still exists using the “indexOf” function. If so, continue to replace, end not to replace, then all target strings have been replaced: