Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Created October 20, 2016 13:28
Show Gist options
  • Save evolutionxbox/31e9dfc1128fcc9f2152c07168d56e0c to your computer and use it in GitHub Desktop.
Save evolutionxbox/31e9dfc1128fcc9f2152c07168d56e0c to your computer and use it in GitHub Desktop.
Find Unicode Chars in String
// Returns array of objects containing the character it found, and it's hexidecimal string value.
function findUnicodeChars(str) {
var arr = str.split('');
return arr.filter(char => {
return (char.charCodeAt(0) > 255) && char;
}).map(char => {
return {
char: char,
code: char.charCodeAt(0).toString(16)
};
});
}
// Usage
findUnicodeChars('lorem ipsum'); // returns: [{char: '', code: 'f138'}]
findUnicodeChars('abc'); // returns: []
// Shortcomings... cannot parse strings with emoji.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment