
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript String - charCodeAt() Method
Description
This method returns a number indicating the Unicode value of the character at the given index.
Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points are a direct match of the ASCII character encoding. charCodeAt() always returns a value that is less than 65,536.
Syntax
Use the following syntax to find the character code at a particular index.
string.charCodeAt(index);
Argument Details
index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.
Return Value
Returns a number indicating the Unicode value of the character at the given index. It returns NaN if the given index is not between 0 and 1 less than the length of the string.
Example
Try the following example.
<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>
Output
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
javascript_strings_object.htm
Advertisements