fromCharCode
fromCharCode() 可接受一個指定的 Unicode 值,然后回傳一個字串,
語法:fromCharCode(num,num....)
- num是必填的,一個或多個Unicode 值,即要創建的字串中的字符的 Unicode 編碼
//H的Unicode編碼:72
const code = String.fromCharCode(72)
console.log(code);//H
charCodeAt
charCodeAt() 方法可回傳指定位置的字符的 Unicode 編碼,這個回傳值是 0 - 65535 之間的整數,
語法 :string.charCodeAt(index)
- index必填,表示字串中某個位置的數字,即字符在字串中的下標;
- 字串中第一個字符的下標是 0,如果 index 是負數,或大于等于字串的長度,則 charCodeAt() 回傳 NaN,
//HELLO WORD
console.log('HELLO WORD'.charCodeAt(0)); //72
console.log('HELLO WORD'.charCodeAt(12)); //NaN
利用fromCharCode()\charCodeAt()方法寫字串加密

上述方法里的escape() 函式可對字串進行編碼,這樣就可以在所有的計算機上讀取該字串,
字串解密

結果:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/257454.html
標籤:其他
