JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




String Function - charAt()


Tutorials Javascript

Topic

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



Explanation

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);
document.write(result);
</script>

Result:

Explanation:
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.





  • A Note
    Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

    Other Links

    web hosting