Skip to content

Instantly share code, notes, and snippets.

@tomoya55
Created September 22, 2012 04:07
Show Gist options
  • Save tomoya55/3765078 to your computer and use it in GitHub Desktop.
Save tomoya55/3765078 to your computer and use it in GitHub Desktop.
Get Unicode Representation of Javascript String
var toUnicode = function(str) {
var hex = str.charCodeAt(0).toString(16).split('');
while(hex.length < 4) hex.splice(0, 0, 0);
return '\"' + '\\u' + hex.join('') + '\"' ;
}
console.log(toUnicode("π"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment