replaceAll() 全部替换
replaceAll()方法接受一个字符串或正则表达式:模式pattern,这是它的第一个参数。第二个参数是模式的替换,参数名为replacement。给定这两个参数,replaceAll()将返回一个新字符串,该字符串是源字符串处理之后的字符串,其中所有pattern都替换为replacement。
replaceAll()方法的工作方式与replace()完全相同,但作用于字符串中的所有出现的pattern,而不仅仅是第一个。
let quote = "all the world's a stage, and all the men and women merely players"; let newQuote = quote.replaceAll("all", "most of"); console.log(newQuote);

浙公网安备 33010602011771号