Home Javascript JavaScript method charCodeAt()
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JavaScript method charCodeAt()

Advertisement
This section illustrates you the use of JavaScript method charCodeAt().

JavaScript method charCodeAt()

     

This section illustrates you the use of JavaScript method charCodeAt(). The charCodeAt() method returns the Unicode of the character at a specified position.

Its syntax is:

string.charCodeAt(index);

An Index should be greater than 0 and less than the length of the string. If you will not specified any index value, it will takes the default value 0.Unicode code points range from 0 to 1,114,111. The charCodeAt() will always return a value that is less than 65,536.

 

 

Here is the code:

<html>
<script>
function charcterCode(){
var st=new String("Welcome to this page");
document.write("The Unicode of the character at position 1 is: "+st.charCodeAt(1));
document.write("<br>");
document.write("The Unicode of the character at position 2 is: "+st.charCodeAt(2));
}
</script>
<h2>Use of method charCodeAt()</h2>
<button onclick="charcterCode();">Character Code</button>
</body>
</html>

Output will be displayed as:

On clicking the button you will get the Unicode of the required character:

Download Source Code:

     

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 27, 2009

Ask Questions?    Discuss: JavaScript method charCodeAt()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com