Skip to content

Commit a16dcf0

Browse files
author
jessicarush
committed
Add: at() method
1 parent 7a2deab commit a16dcf0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arrays.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ console.log(array1);
7474
// [ 'example', 10, true, false ]
7575
```
7676

77+
The `at()` method for arrays in JavaScript was introduced in ECMAScript 2022. This provides a more readable syntax for accessing elements at a specific index, especially with its support for negative indices:
78+
79+
```javascript
80+
const fruit = ['apple', 'orange', 'avocado', 'banana'];
81+
82+
let third = fruit.at(2); // avocado
83+
let last = fruit.at(-1); // banana
84+
```
85+
7786

7887
## Properties
7988

0 commit comments

Comments
 (0)