MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/qg23w3/negative_array_indexing_using_at_method/hi4ctz9/?context=3
r/learnjavascript • u/jd_300 • Oct 26 '21
69 comments sorted by
View all comments
28
Why use the at method when you can just use square bracket notation?
18 u/senocular Oct 26 '21 Because fruits[-1] won't give you "avacado", it will give you undefined -15 u/Gibbo3771 Oct 26 '21 fruits[fruits.length - 1]This is what people mean, no one expects [-1] to work. 16 u/VikaashHarichandran Oct 26 '21 People coming from other scripting languages do expect
18
Because fruits[-1] won't give you "avacado", it will give you undefined
undefined
-15 u/Gibbo3771 Oct 26 '21 fruits[fruits.length - 1]This is what people mean, no one expects [-1] to work. 16 u/VikaashHarichandran Oct 26 '21 People coming from other scripting languages do expect
-15
fruits[fruits.length - 1]
This is what people mean, no one expects [-1] to work.
[-1]
16 u/VikaashHarichandran Oct 26 '21 People coming from other scripting languages do expect
16
People coming from other scripting languages do expect
28
u/HyerOneNA Oct 26 '21
Why use the at method when you can just use square bracket notation?