Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




charCodeAt() - FUNCTION


charCodeAt() Function


The charCodeAt(..) function is used to return us the ascii code of a particular character of a String if we supply it with index value.


Say, if we want to know the ASCII code of the letter/character that is present at 2nd index of the String "World".


Assuming the count starts from 0.


Example :



<html>
<body>  
<script>

	var firstString = "World"
	var pos = firstString.charCodeAt(2)
	document.write("The ASCII code of the character is : ", pos)
    
</script>      
</body>
</html>


Output :



  The ASCII code of the character is : 114

So, in the above code, we have a String World initialised to a variable x.

java_Collections

Then we have used the charCodeAt() Function to get the ASCII code of the letter at index 2.


var pos = firstString.charCodeAt(2)
java_Collections


And as we can see, the letter at index 2 is r. And the ASCII code for r is 114.


So, 114 is taken and put into the variable pos.

java_Collections