Difference Between Array.at and Array[idx]

--- title: 'Difference Between Array.at and Array[idx]' author: 'Hun Im' date: 2024-08-02T11:53:04+09:00 category: ['POSTS'] tags: ['Algorithm', 'Javascript'] og_image: "/images/gamer.png" keywords: ['Javascript', 'Algorithm'] --- `Array.at(idx)` is a method introduced in `ES2022`. Let's explore the differences between the traditional Array[idx] and Array.at(idx). **Differences** The most significant difference is the support for negative indices. ```js const arr = [10, 20, 30] console.log(arr[-1]) // undefined const arr = [10, 20, 30] console.log(arr.at(-1)) // 30 ```
Β 
--- title: 'Array.atκ³Ό Array[idx]의 차이' author: 'μž„ν›ˆ' date: 2024-08-02T11:53:04+09:00 category: ['POSTS'] tags: ['Algorithm', 'Javascript'] og_image: "/images/gamer.png" keywords: ['Javascript', 'Algorithm'] --- `Array.at(idx)`은 `es2022`λΆ€ν„° λ“±μž₯ν•œ λ©”μ†Œλ“œμ΄λ‹€. κΈ°μ‘΄ λ°©μ‹μ˜ `Array[idx]`κ³Ό μ–΄λ–€ 차이가 μžˆλŠ”μ§€ μ•Œμ•„λ³΄μž. **차이** κ°€μž₯ κ·Ήλͺ…ν•œ μ°¨μ΄λŠ” 음수 인덱슀 지원에 μžˆλ‹€. ```js const arr = [10, 20, 30] console.log(arr[-1]) // undefined const arr = [10, 20, 30] console.log(arr.at(-1)) // 30 ```