Published Jul 30, 2023
Contribute to Docs

The .at() method in JavaScript is used to return the element at a specified index in an array. The index can be either positive or negative (negative indices count from the end of the array).


  • index: The index value of the element to be returned.


The example below demonstrates how to use the .at() function to extract an element from an array based on an index.

const array = [1, 2, 3, 4, 5];
const firstElement = array.at(0);

This example results in the following output:


All contributors

Looking to contribute?

Learn JavaScript on Codecademy