JavaScript natively supports replaceAll Author: Chuwen Time: 2020-06-24 Classification: Other classifications See MDN for details: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll >The 'replaceAll()' method returns a new string, all of which meet the requirements; Pattern matching is replaced by; Replaced. The pattern can be a string or a 'RegExp', and the replacement can be a string or a function to be called every time a match is made. #However, the compatibility is very low. Only Chrome 85, Firefox 77 and Safari 13.1 start to support it ! [Snipaste_2020-06-24_16-23-06.png][1] #Chrome 85 running results ``` I 66 you 66 ah ". replace (" 66 "," like "); >>>"I like you 66 ah" "I 66 you 66 ah". replaceAll ("66", "like"); >>>"I like it You like it" ``` ! [Snipaste_2020-06-24_16-28-26.png][2] #Of course, you can also use replace to achieve similar functions ``` "I 666, you 666". replace (/666/g, "like"); >>>"I like it You like it" "I {{$tmp}} you {{$tmp}}". replace (/{{ $tmp}}}/g, "like"); >>>"I like it You like it" ``` [1]: https://cdn.nowtime.cc/2020/06/24/3937386759.png [2]: https://cdn.nowtime.cc/2020/06/24/4110438231.png Label: none