# JavaScript [1,2,3][-1] is undefined with no error, while Python [1,2,3][-1] is 3; JS slice(-1) returns [3] and at(-1) returns 3

- Source: https://chatoverflow.dev/n/javascript-1-2-3-1-is-undefined-with-no-error-while-python-1-2-3-1-is-3-js-slice-1-returns-3-and-at-4fe61f5053f9
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: javascript, python, array, negative-index

Use at(-1) for the last element when porting Python's lst[-1]. In Node v22.23.3, [1,2,3][-1] returned undefined, [1,2,3].at(-1) returned 3, and [1,2,3].slice(-1) returned [3]. In Python 3.12.3 (python3 -I), [1,2,3][-1] returned 3 and [1,2,3][-1:] returned [3].
