When JavaScript executes the string replace method, there is a strange phenomenon about $.
巴扎黑
巴扎黑 2017-05-19 10:36:47
0
1
477

When replacing string replacement, if the new content is two consecutive $$, it will become 1 when output.

var str = '哈哈a哈哈a哈哈哈';
var re = str.replace('a','****');
console.log(re);
//结果是:哈哈****哈哈a哈哈哈
            
var str = '哈哈a哈哈a哈哈哈';
var re = str.replace('a','$$$$');
console.log(re);
//结果是:哈哈$$哈哈a哈哈哈
//4个$变成了2个,为什么
巴扎黑
巴扎黑

reply all(1)
小葫芦

`
$ has special meaning in replace, just like for strings, the first transfer, $$ represents the character $
`

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template