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.
charAt() |
Yes | Yes | Yes | Yes | Yes |
stringObject.charAt(index);
Parameter | Description |
---|---|
index | Required. An integer based character index. |
A string of the character at the specified index.
It returns an empty string if the index is not found.
var stringValue = "hello world";
console.log(stringValue.charAt(1)); //"e"
The code above generates the following result.