Posted By

Sephr on 03/12/09


Tagged

String js16 charCode


Versions (?)

string.toCharCodes & String.fromCharCodes [JS 1.6]


 / Published in: JavaScript
 

Requires JavaScript 1.6 or higher

Syntax:

Array string.toCharCodes() returns an array containing every one of string's character codes, in order.

String String.fromCharCodes(charCodes) returns a string created from every character code in the array, charCodes.

  1. String.prototype.toCharCodes = function toCharCodes() {
  2. return Array.prototype.map.call(this, function(str) {
  3. return str.charCodeAt(0)
  4. })
  5. };
  6.  
  7. String.fromCharCodes = function fromCharCodes(charCodes) {
  8. return String.fromCharCode.apply(this, charCodes)
  9. };

Report this snippet  

You need to login to post a comment.