Home » JavaScript

JavaScript String charCodeAt() Method with Example

JavaScript String charCodeAt() Method: Here, we are going to learn about the charCodeAt() method in JavaScript with Example.
Submitted by IncludeHelp, on February 06, 2019

String charCodeAt() Method

charCodeAt() Method is a string method in JavaScript, it is used to get the Unicode of character at the specified index in the string.

It accepts an index of the character and returns it's Unicode.

Note: If the index is not valid, it returns NaN. Read more: NaN in JavaScript.

Syntax:

    String.charCodeAt(index);

Here,

  • String is the main string.
  • index is the position of the character in the string.

Examples:

    Input: 
    str = "IncludeHelp"
    index = 0
    Output:
    73

    Input: 
    str = "IncludeHelp"
    index = 5
    Output:
    100

Code:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
<script>		
	var str = "IncludeHelp";
	
	var unicode = str.charCodeAt(0);
	document.write(unicode + "<br>");
	
	unicode = str.charCodeAt(5);
	document.write(unicode + "<br>");

	unicode = str.charCodeAt(-1);
	document.write(unicode + "<br>");

	unicode = str.charCodeAt(100);
	document.write(unicode + "<br>");	
</script>
</body>
</html>

Output

73
100
NaN
NaN





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.