Created
July 30, 2018 10:27
-
-
Save lucymtc/0f396a8749d448fea28c00b51d25c24b to your computer and use it in GitHub Desktop.
JavaScript - String to Unicode
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) => { | |
| let unicodeString = ''; | |
| for (var i = 0; i < str.length; i ++) { | |
| let unicodeStr = str.charCodeAt(i).toString(16).toUpperCase(); | |
| while (unicodeStr.length < 4) { | |
| unicodeStr = `0${unicodeStr}`; | |
| } | |
| unicodeStr = `\\u${unicodeStr}`; | |
| unicodeString += unicodeStr; | |
| } | |
| return unicodeString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment