String Function - charAt()

function or method to find the character at a position in a string using javascript?


Object: String
Method or Function: charAt(int)
Description: This method takes an integer value as argument and returns the character at that position in the string. The positioning of the string starts from zero to n. i.e. The first character of the string is assumed to be at position zero (0), next at 1 and so on.

Example Code:
<script language=javascript>
var ss = "a string test ";
var result = ss.charAt(3);


In the above example,
  • the string is stored in a variable ss.
  • then we called the function or method charAt(3), to get the character at position 3 in the string.
  • the positioning is as 0-a, 1- , 2-r, 3-t, ....
  • character at position 3 is 't' and so 't' is returned as result.
  • the result is of variable type, string.

Ask Questions

Ask Question