MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/qg23w3/negative_array_indexing_using_at_method/hi6a6in/?context=9999
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. 19 u/greymalik Oct 26 '21 People coming from Python or Ruby expect it. -13 u/doyouseewhateyesee Oct 26 '21 people coming from python or ruby should read the docs -1 u/Tintin_Quarentino Oct 26 '21 Lmao
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. 19 u/greymalik Oct 26 '21 People coming from Python or Ruby expect it. -13 u/doyouseewhateyesee Oct 26 '21 people coming from python or ruby should read the docs -1 u/Tintin_Quarentino Oct 26 '21 Lmao
-15
fruits[fruits.length - 1]
This is what people mean, no one expects [-1] to work.
[-1]
19 u/greymalik Oct 26 '21 People coming from Python or Ruby expect it. -13 u/doyouseewhateyesee Oct 26 '21 people coming from python or ruby should read the docs -1 u/Tintin_Quarentino Oct 26 '21 Lmao
19
People coming from Python or Ruby expect it.
-13 u/doyouseewhateyesee Oct 26 '21 people coming from python or ruby should read the docs -1 u/Tintin_Quarentino Oct 26 '21 Lmao
-13
people coming from python or ruby should read the docs
-1 u/Tintin_Quarentino Oct 26 '21 Lmao
-1
Lmao
28
u/HyerOneNA Oct 26 '21
Why use the at method when you can just use square bracket notation?