Tag Archives: Prototype

String.protototype.toCharCodes()

One of the functions that didn’t make the cut for jPaq is String.prototype.toCharCodes().  The reason is I don’t feel that it is a function that many people are looking for.  Still, if you are looking for a good implementation for it, you can use this:

String.prototype.toCharCodes = function() {
  for(var arr = this.split(""), i = this.length - 1; i >= 0; i--)
    arr[i] = arr[i].charCodeAt(0);
  return arr;
};