TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript String charCodeAt() Method

JavaScript string charCodeAt() Method with example, by string literal, by string object (using new keyword), javascript string methods, charAt(index) method, concat(str) method, indexOf(str) method, lastIndexOf(str) method, lowerCase() method, upperCase() method, slice(beginIndex, endIndex) method, trim() method, toLowerCase(), slice(), concat(), charCodeAt() method etc.

<< Back to JAVASCRIPT

JavaScript String charCodeAt() Method

The JavaScript string charCodeAt() method is used to find out the Unicode value of a character at the specific index in a string.

The index number starts from 0 and goes to n-1, where n is the length of the string. It returns NaN if the given index number is either a negative number or it is greater than or equal to the length of the string.

Syntax

The charCodeAt() method is represented by the following syntax:

string.charCodeAt(index)

Parameter

index - It represent the position of a character.

Return

A Unicode value

JavaScript String charCodeAt() Method Example

Let's see some simple examples of charCodeAt() method.

Example 1

Here, we will print the Unicode value of a character by passing its specific index.

<script>
var x="TheDeveloperBlog";
document.writeln(x.charCodeAt(3));
</script>
Test it Now

Output:

97

Example 2

In this example, we will not pass any index number with the method. In such case, it will return the Unicode value of first character.

<script>
var x="TheDeveloperBlog";
document.writeln(x.charCodeAt());//It will return Unicode value of 'J'
</script>
Test it Now

Output:

74

Example 3

Here, we will print the Unicode value of last character in a string.

<script>
var x="TheDeveloperBlog";
document.writeln(x.charCodeAt(x.length-1));
</script>
Test it Now

Output:

116

Example 4

Here, we will provide the index number greater than the length of the string. In such case, the method returns NaN.

<script>
var x="TheDeveloperBlog";
document.writeln(x.charCodeAt(12));
 </script>
Test it Now

Output:

NaN

Next TopicJavaScript String




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf