Skip to content

Instantly share code, notes, and snippets.

@sergeevabc
Created October 19, 2014 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeevabc/e6758ef74f8ff3e9dbae to your computer and use it in GitHub Desktop.
Save sergeevabc/e6758ef74f8ff3e9dbae to your computer and use it in GitHub Desktop.
Count bytes in array
function getByteCount(s) {
var count = 0,
stringLength = s.length,
i;
s = String(s || "");
for (i = 0; i < stringLength; i++) {
var partCount = encodeURI(s[i]).split("%").length;
count += partCount == 1 ? 1 : partCount - 1;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment