开发者

How to reverse String.fromCharCode?

String.fromCharCode(72) gives H. How开发者_高级运维 to get number 72 from char H?


'H'.charCodeAt(0)


Use charCodeAt:

var str = 'H';
var charcode = str.charCodeAt(0);


@Silvio's answer is only true for code points up to 0xFFFF (which in the end is the maximum that String.fromCharCode can output). You can't always assume the length of a character is one:

'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜