at(index) truy cập phần tử với hỗ trợ negative index: arr.at(-1) lấy phần tử cuối, arr.at(-2) lấy phần tử áp cuối. Thay cho arr[arr.length - 1] vốn dài và dễ nhầm. Hoạt động với Array, String và TypedArray — 'hello'.at(-1) trả về 'o'. Hỗ trợ trên tất cả modern browsers từ 2022.
Không thể dùng arr[-1] vì JS coi -1 là string key của object — đây là bẫy phỏng vấn phổ biến.
at(index) accesses an element with support for negative indices: arr.at(-1) gets the last element, arr.at(-2) the second-to-last. Replaces arr[arr.length - 1] which is verbose and error-prone. Works identically for Array, String, and TypedArray — 'hello'.at(-1) returns 'o'. Supported in all modern browsers since 2022.
You cannot use arr[-1] because JS treats -1 as a string object key — a common interview trap.