← TechnologyThe essentials of

at(): the last element without index calculus

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The negative index counts from the end of the array.

Useful to know

at() returns an element by index, allowing negative indices. For example, [4, 7, 9].at(-1) returns 9, and .at(-2) - 7. In index outside the available elements the result is undefined. [1]

This is convenient for a last saved value when an empty array is an eligible case. Check the missing score before reading its property. Unlike .at(-1), the array[-1] entry looks for a property named "-1"; it is not another syntax for the last element.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.at ↗