Negative indexes
# Jeremy Martin (9 years ago)
A similar proposal was recently brought up - please check out esdiscuss.org/topic/javascript-language-feature-idea to browse the existing conversation on it.
# C. Scott Ananian (9 years ago)
arr.slice(-1)[0]
does what you want, I think.
--scott
# Felipe Nascimento de Moura (9 years ago)
Yes, that would do what he wants...but I like the idea of using
arr[-1]
, though!!
It just makes sense, to me!
Specially if you want to use reversed loops, for example.
# Logan Smyth (9 years ago)
Felipe, this has been discussed in the other thread that was just linked:
esdiscuss.org/topic/javascript-language-feature-idea. arr[-1]
is
not a workable solution because it could break existing code.
# Felipe Nascimento de Moura (9 years ago)
hm...yep...you are right!
It would be great if we could use negative indexes, -1 being the index of the last element of an Array or of an Array-like object . Also, an alias for console.log would be more than welcome.