其他分享
首页 > 其他分享> > js常用API

js常用API

作者:互联网

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录


1.字符和数字相互转换

String.fromCharCode()
静态 String.fromCharCode() 方法返回由指定的 UTF-16 代码单元序列创建的字符串。

console.log(String.fromCharCode(65, 43, 97, 61));
//"A+a="

String.prototype.charCodeAt()
charCodeAt() 方法返回 0 到 65535 之间的整数,表示给定索引处的 UTF-16 代码单元

const sentence = 'The quick brown fox jumps over the lazy dog.';
const index = 4;
console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(2)}`);
// expected output: "The character code 113 is equal to e"

标签:常用,code,String,sentence,character,js,API,charCodeAt,fromCharCode
来源: https://blog.csdn.net/weixin_43593989/article/details/120593778