JavaScript String at()
- Previous Page at()
- Next Page charAt()
- Go to the Previous Level JavaScript String Reference Manual
Definition and Usage
at()
Method returns the character at the specified index position from the string.
at()
Method with []
has the same effect.
Example
Example 1
Get the first character of the text:
let text = "W3School"; let character = text.at(0);
Example 2
Get the first character of the text:
let text = "W3School"; let character = text[0];
Example 3
Get the first character of the text:
let text = "W3School"; let character = text.at();
Example 4
Get the last character of the text:
let text = "W3School"; let character = text.at(-1);
Syntax
string.at(index)
Parameter
Parameter | Description |
---|---|
index |
Optional. Specifies the index (position) of the character to return. Default value is 0. -1 means to return the last character. |
Return Value
Type | Description |
---|---|
String | Single character. Returns the character at the specified index position in the string. |
Browser Support
JavaScript String at()
Supported in all browsers since March 2022:
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 66 | Edge 79 | Firefox 61 | Safari 12 | Opera 50 |
July 2021 | July 2021 | July 2021 | March 2022 | August 2021 |
- Previous Page at()
- Next Page charAt()
- Go to the Previous Level JavaScript String Reference Manual