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




charAt() - FUNCTION


charAt() Function


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


Say, if we want to know which character 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.charAt(2)
	document.write("The character is : ", pos)
    
</script>      
</body>
</html>


Output :



  The character is : r

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

java_Collections

Then we have used the charAt() Function to get the letter at index 2.


var pos = firstString.charAt(2)
java_Collections


And as we can see, the letter at index 2 is r.


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

java_Collections