×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

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);

Parameters

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

Sample Input/Output

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

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

Example

<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

JavaScript String Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.