這代碼看不懂 不知道是怎么得出的這個結果
請問有人知道這個代碼是怎么回事嗎?
'a1b2c3d4e'.replace(/\d/g,function(match,index,origin){
console.log(index)
return parseint(match)+1;})
返回:13579
"a2b3c4d5e6"
這里面的origin是什么意思???
還有這個function(match,index,origin不太懂什么意思
'a1b2c3d4e'.replace(/\d/g,function(match,index,origin){
console.log(index)
return parseint(match)+1;})
返回:13579
"a2b3c4d5e6"
這里面的origin是什么意思???
還有這個function(match,index,origin不太懂什么意思
2019-09-24
舉報
2019-09-28
orgin代表的是原字符串,該方法主要用于對一段字符串匹配后再對其中的部分字符串做特殊處理。
2019-11-14
function中的三個參數:match代表匹配項,比如字符串中的數字1、2、3、4;index代表匹配項的索引,這里就是那四個數字的索引1、3、5、7;origin代表調用replace的原字符串,這里就是前面的‘a1b2c3d4e’,在這里調用這個函數可以對字符串匹配項做其他操作。PS:打印出來的應該沒有9吧。。