1. 中文和unicode相互转换

// 中文 转  unicode
function chinese_to_unicode(ch,is16 = false) {
    let num_ten = ch.charCodeAt(ch);
    if(is16){
        return '0x' + num_ten.toString(16);
    }else{
        return num_ten.toString();
    }
}

// unicode 转 中文
function unicode_to_chinese(lstUnicode) {
    return String.fromCharCode(lstUnicode);
}


// console.log(chinese_to_unicode('张'));
// console.log(unicode_to_chinese([0x5f20]));
原文地址:https://www.cnblogs.com/daihanlong/p/11714238.html