2025年02月01日 建站教程
js如何利用replaceAll方法批量替换全文指定文字,下面web建站小编给大家详细介绍一下具体实现代码!
replaceAll方法:
let str = 'web建站小编给大家简单介绍一下web是如何运用的!'.replaceAll("web", "vue") console.log('输出结果:',str) //输出结果: vue建站小编给大家简单介绍一下vue是如何运用的!
RegExp方法:
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
let result = replaceAll("'web建站小编给大家简单介绍一下web是如何运用的!","web", "vue");
console.log('输出结果:',result); //输出结果: 'vue建站小编给大家简单介绍一下vue是如何运用的!
本文链接:http://so.lmcjl.com/news/22442/