合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
要替换字符串中所有出现的特定子字符串,您可以使用正则表达式方法与全局标志的替换,或使用新的replaceAll方法(注意:并非所有浏览器和Node.js版本都支持)。 ``` // Use the replace method combined with a regular expression with global flags to replace all occurrences of a string. const str = "I love JavaScript, JavaScript is amazing!"; console.log(str.replace(/JavaScript/g, "Node.js")); // "I love Node.js, Node.js is amazing!" ```