js 计算字符串字节长度

_getByteLen(v) {
    var len = 0;
    for (var i = 0; i < v.length; i++) {
        var a = v.charAt(i);
        if (a.match(/[^x00-xff]/ig) != null)
        {
            len += 2;
        }
        else
        {
            len += 1;
        }
    }
    return len;
}

摘自:https://blog.csdn.net/qq_31393401/article/details/81978543

原文地址:https://www.cnblogs.com/hjbky/p/14805049.html