JavaScript String at()
Examples
Get the first character of the text:
let text = "W3Schools";
let character = text.at(0);
Try it Yourself »
Get the first character of the text:
let text = "W3Schools";
let character = text[0];
Try it Yourself »
More examples below.
Description
The at()
method returns an indexed character from a string.
The at()
method returns the same as []
.
Syntax
string.at(index)
Parameters
Parameter | Description |
index | Optional. The index (position) of the character to be returned. Default is 0. -1 returns the last character. |
Return Value
Type | Description |
A String | A single character. The character in the given position (index) in the string. |
Browser Support
JavaScript String at()
is supported in all browsers since March 2022:
Chrome 66 | Edge 79 | Firefox 61 | Safari 12 | Opera 50 |
Jul 2021 | Jul 2021 | Jul 2021 | Mar 2022 | Aug 2021 |
More Examples
Get the first character of the text:
let text = "W3Schools";
let character = text.at();
Try it Yourself »
Get the last character of the text:
let text = "W3Schools";
let character = text.at(-1);
Try it Yourself »
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.