string.toCharCodes & String.fromCharCodes [JS 1.6]


/ Published in: JavaScript
Save to your folder(s)

*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`.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.