字符串常见API(charCodeAt\fromCharCode)

1.myStr.charCodeAt(num)
返回指定位置的字符的Unicode(是字符编码的一种模式)编码。
2.String.fromCharCode()
   String的意思就是不能用自己定义的字符串名字来调用,只能用String来定义调用。接受一个或多个指定的Unicode值,然后返回一个或多个字符串。(把unicode编码转换为字符串)。
 var str = "中国";
     console.log(String.fromCharCode("0x4E2D"))

     console.log(String.fromCharCode(20013))

     console.log(String.fromCharCode("\u4E2D"))

     var str = "a";
     var str = "b";
     console.log(str.charCodeAt(0));

    // 65~90
//    console.log(String.fromCharCode(random(65,90)))
//
//    function random(a,b){
//        return Math.round(Math.random()*(a-b)+b)
//    }

 

posted @ 2019-08-22 23:26  菜鸟小何  阅读(671)  评论(0编辑  收藏  举报