Created
October 19, 2014 23:03
-
-
Save sergeevabc/e6758ef74f8ff3e9dbae to your computer and use it in GitHub Desktop.
Count bytes in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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