JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow String Right Arrow charAt()

charAt()  String  instance method

Description

Returns the character at the specified index.

Syntax


Signature Description
aString.charAt(index)Returns the character at the specified index.

Parameters


Parameter Description
indexAn integer between 0 and the length of the string -1.
  • Out of range indexes return an empty string.

Examples

The code below creates a string of the alphabet and returns index 19.


// Create alphabet string varible.
var theAlphabet = 'abcdefghijklmnopqrstuvwxyz';
// Return character at index 19 ('t').
alert(theAlphabet.charAt(19));

Press the button below to action the above code:

Related Tutorials

JavaScript Basic Tutorials - Lesson 8 - Strings



  

go to home page Homepage go to top of page Top