Javascript - String.charAt()

 

Syntax

string.charAt(num)

Description

The charAt() method of an instance of the String object returns the character located at the indexed, num, position passed. This indexing is done from left to right starting with the 0(zero) position. If the num passed is not a valid index in the string, -1 is returned.

Example

<script language="JavaScript">
<!--

var myString = new String("abc defg");

document.write(myString.charAt(2)); //result is 'c'
document.write(myString.charAt(7)); //result is 'g'
document.write(myString.charAt(9)); //result is -1

//-->
</script>

 

 
Visitor Review  Write a review

sowmya on 04 May 2008 10:34 reply

excellent

 
See all reviews
Write a review
Rating:
Text:
Name:
Email:
(optional)
 
Code:
 

Search this site