at(index)
index < -array.length
또는 index >= array.length
인 경우undefined
반환arr.at(-1)
== arr[arr.length - 1]
arr.at(-3)
== arr[arr.length - 3]
== arr.slice(-3, -1)[0]
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"