-
-
Save shhider/8c19ede4cca3aa70729e2d0fe03fb6b8 to your computer and use it in GitHub Desktop.
[JavaScript convert string to unicode format] #tounicode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toUnicode = (str) => str.split('').map((char) => { | |
const temp = char.charCodeAt(0).toString(16).toUpperCase(); | |
if (temp.length > 2) { | |
return '\\u' + temp; | |
} | |
return char; | |
}).join(''); | |
console.log(toUnicode('转换成 Unicode')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment