標簽:方式 mic com def console int() char code 結果
s=‘abcdef‘
console.log(s.charAt(0))
//a
注意:只能讀,不能寫
s=‘abcdef‘
s.charAt(0)=‘c‘
console.log(s)
运行結果
現在能想到的修改字符串中某個字符的方式就是將字符串轉爲數組。。或直接拼接等其他效率較低的方式
s=‘abcdef‘
console.log(s.charCodeAt(0))
//97
charCodeAt方法的逆作用,傳入字符編碼值,將字符編碼值轉爲對應的字符
let a=String.fromCharCode(97)
console.log(a)
//a
let a=String.fromCharCode(97,97)
console.log(a)
//aa
fromCharCode()不能對大于0xFFFF的值實現編碼,不能單獨獲取在高代碼點位上的字符,fromCodePoint()是es6新出的字符串方法,可屹滵換圖標字符。
String.fromCodePoint(0x1D306, 0x61, 0x1D307)
js中的charAt()與charCodeAt(),fromCharCode(),fromCodePoint()
標簽:方式 mic com def console int() char code 結果
原文地址:https://www.cnblogs.com/xu0428/p/14966096.html