String to UTF8 Byte Array - Node.js String

Node.js examples for String:Unicode

Description

String to UTF8 Byte Array

Demo Code


if (typeof String.prototype.toUTF8ByteArray != 'function')
String.prototype.toUTF8ByteArray = function() {
  var bytes = [];

  var s = unescape(encodeURIComponent(this));

  for (var i = 0; i < s.length; i++) {
    var c = s.charCodeAt(i);
    bytes.push(c);/*  w  w  w.  j ava  2  s  . c o m*/
  }

  return bytes;
};

Related Tutorials