On this page
Array.at
Prev: some | Up: Array | Next: toSorted
Rel: Array, Array & Typed Arrays Guide
Ref: MDN Web Docs — Array.at
Tags: #public #web #javascript #builtins #array #tier/core
Signature & Overview
arr.at(index)
Returns the element at index, supporting negative indexing from the end (arr.at(-1)).
Notes & Pitfalls
- Supports negative indexing (
arr.at(-1)): Cleaner thanarr[arr.length - 1]and returnsundefinedwhen out of bounds. - Works on strings and TypedArrays too (
"abc".at(-1) === "c").
Example
const items = ["first", "middle", "last"];
console.assert(items.at(0) === "first");
console.assert(items.at(-1) === "last");
console.assert(items.at(99) === undefined);
Linked from
Related notes
- tuts/javascript/builtins/Array/some Linked here; links to this page; shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/toSorted Linked here; links to this page; shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array Linked here; links to this page; shared tags: #array, #builtins, #javascript, #web
- tuts/javascript/builtins/array_and_typed_arrays Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/Array/filter shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/find shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/flatMap shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/from shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/includes shared tags: #array, #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/isArray shared tags: #array, #builtins, #javascript, #tier, #web