String.prototype.getBytes

by Noncho Savov

JavaScript

String.prototype.getBytes = function () {
  var bytes = [];
  for (var i = 0; i < this.length; ++i) {
    bytes.push(this.charCodeAt(i));
  }
  return bytes;
};

var str = "Hello World!";
var bytes = str.getBytes();

console.log(bytes);