encode - Node.js convert Chinese character to \uXXXX -


i want convert string '字符串' '\u5b57\u7b26\u4e32', how implement in node.js?

function convert(str) {     //... }  var s = '字符串' convert(s); // => \u5b57\u7b26\u4e32 

this can done in better way (and mentioned jsesc safer choice):

function convert(s) {   return s.split('').map(function(c) {     return '\\u' + ('0000' + c.charcodeat(0).tostring(16).touppercase()).slice(-4);   }).join(''); }  var s = '字符串'; convert(s) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -