| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/at | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2022 3.
Array at() , . .
const array1 = [5, 12, 8, 130, 44];
let index = 2;
console.log(`An index of ${index} returns ${array1.at(index)}`);
// Expected output: "An index of 2 returns 8"
index = -2;
console.log(`An index of ${index} returns ${array1.at(index)}`);
// Expected output: "An index of -2 returns 130"
at(index)
. index < -array.length index >= array.length , undefined .
, at() . , array[0] array.at(0) . Python R array[-1] . array["-1"] . .
length , (: array[array.length - 1]). at() array.at(-1) .
at() with() .
.
//
const cart = ["", "", ""];
//
function returnLast(arr) {
return arr.at(-1);
}
// 'cart'
const item1 = returnLast(cart);
console.log(item1); // ''
// 'cart'
cart.push("");
const item2 = returnLast(cart);
console.log(item2); // ''
Array . at() .
//
const colors = ["", "", ""];
// length
const lengthWay = colors[colors.length - 2];
console.log(lengthWay); // ''
// slice() .
const sliceWay = colors.slice(-2, -1);
console.log(sliceWay[0]); // ''
// at()
const atWay = colors.at(-2);
console.log(atWay); // ''
at() this length .
const arrayLike = {
length: 2,
0: "a",
1: "b",
2: "c", // length 2 at() .
};
console.log(Array.prototype.at.call(arrayLike, 0)); // "a"
console.log(Array.prototype.at.call(arrayLike, 2)); // undefined
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.at |
core-js Array.prototype.at ArrayArray.prototype.findIndex()Array.prototype.indexOf()TypedArray.prototype.at()String.prototype.at()This page was last modified on 2025 10 10 by MDN contributors.
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |