简体   繁体   中英

How to shorten this JavaScript code [replace / regex]

The job of this code is to convert any number in the text into Unicode and the number itself.

This is the code below

"5H6i".replace(/[1-9]/g, function(match) {return match + String.fromCharCode(Number(match) + 32)});

for example:

3H4i Converted to 3#H4$i

I don't know why you want it shorter, it's fine as it is. But here you go

"5H6i".replace(/[1-9]/g, match => match + String.fromCharCode(Number(match) + 32))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM