Javascript Reference - JavaScript String charAt() Method








charAt() accepts zero-based position as its only parameter. It returns the character in the given position.

The index of the first character is 0, the second character is 1.

The index of the last character in a string is string.length - 1.

Browser Support

charAt() Yes Yes Yes Yes Yes

Syntax

stringObject.charAt(index);




Parameter Values

Parameter Description
index Required. An integer based character index.

Return Value

A string of the character at the specified index.

It returns an empty string if the index is not found.

Example


var stringValue = "hello world"; 
console.log(stringValue.charAt(1)); //"e" 

The code above generates the following result.