Skip to content

Instantly share code, notes, and snippets.

@spoike
Created September 24, 2013 13:39
Show Gist options
  • Select an option

  • Save spoike/6684846 to your computer and use it in GitHub Desktop.

Select an option

Save spoike/6684846 to your computer and use it in GitHub Desktop.
String to array of charcodes
var toCodes = function(str) {
var i, carr = [];
for(i = 0; i < str.length; i++) {
carr.push(str.charCodeAt(i));
}
return carr;
};
toCodes("hahah"); // outputs [104, 97, 104, 97, 104]
toCodes("Hahah hah!"); // outputs [72, 97, 104, 97, 104, 32, 104, 97, 104, 33]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment