Get the App
SLTechnology News&Howtos  ›  Development  › 

How to replace all of JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:21:33 10月03日 Update

This article mainly introduces how to achieve full replacement of JavaScript, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Replace all

The String.replace () function allows you to replace strings with String and Regex, and this function itself can only replace the first matching string. But you can add / g to the end of the regular expression to simulate the replaceAll () function:

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 this article carefully. I hope the article "how to replace all JavaScript" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles functions values interests at the same time characters strings more friends end regularity knowledge editing industry expressions information information channels channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei vpn Shulou Technology Shulou Tech Info