JavaSacript中charCodeAt()方法的使用詳解
該方法返回一個數(shù)字,表示給定索引處的字符的Unicode值。
Unicode碼點范圍為0到1114111。前128個Unicode碼點的ASCII字符編碼的直接匹配。charCodeAt()將始終返回一個值小于65,536。
語法
string.charCodeAt(index);
下面是參數(shù)的詳細(xì)信息:
- index: 0和1之間小于字符串的長度的整數(shù); 如果未指定,默認(rèn)為0。
返回值:
返回一個數(shù)字,表示給定索引處的字符的Unicode值。如果給定的索引不是0和1之間的長度,返回NaN。
例子:
<html> <head> <title>JavaScript String charCodeAt() Method</title> </head> <body> <script type="text/javascript"> var str = new String( "This is string" ); document.write("str.charCodeAt(0) is:" + str.charCodeAt(0)); document.write("<br />str.charCodeAt(1) is:" + str.charCodeAt(1)); document.write("<br />str.charCodeAt(2) is:" + str.charCodeAt(2)); document.write("<br />str.charCodeAt(3) is:" + str.charCodeAt(3)); document.write("<br />str.charCodeAt(4) is:" + str.charCodeAt(4)); document.write("<br />str.charCodeAt(5) is:" + str.charCodeAt(5)); </script> </body> </html>
這將產(chǎn)生以下結(jié)果:
str.charCodeAt(0) is:84 str.charCodeAt(1) is:104 str.charCodeAt(2) is:105 str.charCodeAt(3) is:115 str.charCodeAt(4) is:32 str.charCodeAt(5) is:105
相關(guān)文章
在JavaScript中使用對數(shù)Math.log()方法的教程
這篇文章主要介紹了在JavaScript中使用對數(shù)Math.log()方法的教程,是JS入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-06-06JavaScript中g(shù)etUTCSeconds()方法的使用詳解
這篇文章主要介紹了JavaScript中g(shù)etUTCSeconds()方法的使用詳解,是JS入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-06-06關(guān)于不同頁面之間實現(xiàn)參數(shù)傳遞的幾種方式討論
下面小編就為大家?guī)硪黄P(guān)于不同頁面之間實現(xiàn)參數(shù)傳遞的幾種方式討論。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02JavaScript中的prototype和constructor簡明總結(jié)
一直沒弄清楚JavaScript中的prototype和constructor屬性,今天看了看書,總算有點眉目了2014-04-04javascript中interval與setTimeOut的區(qū)別示例介紹
這篇文章主要介紹了javascript中interval與setTimeOut的區(qū)別,需要的朋友可以參考下2014-03-03深入解析JavaScript編程中的this關(guān)鍵字使用
這篇文章主要介紹了深入解析JavaScript編程中的this關(guān)鍵字使用,是JS入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-11-11JavaScript_object基礎(chǔ)入門(必看篇)
下面小編就為大家?guī)硪黄狫avaScript_object基礎(chǔ)入門(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06