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
@aiden-f-dsouza▲ -12 net votes
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].