Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
The .at() method lets you access elements with negative indices! Use .at(-1) for the last element,.at(-2) for second-to-last. Works on arrays and strings!
arr[arr.length - 1]. Now: arr.at(-1). Much cleaner!Use positive and negative indices
Practical scenarios for .at()
Count from the end: -1 is last, -2 is second-to-last
Replace arr[arr.length-1] with arr.at(-1)
Both arrays and strings support .at()
Modern convenience method