Negative indexes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Negative indexes

Lich
Hi! 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.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Negative indexes

Jeremy Martin
A similar proposal was recently brought up - please check out https://esdiscuss.org/topic/javascript-language-feature-idea to browse the existing conversation on it.

On Mon, Feb 1, 2016 at 2:35 PM, Lich <[hidden email]> wrote:
Hi! 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.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
661.312.3853
@jmar777

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Negative indexes

C. Scott Ananian
In reply to this post by Lich
`arr.slice(-1)[0]` does what you want, I think.
 --scott

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Negative indexes

Felipe Nascimento de Moura
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.



On Mon, Feb 1, 2016 at 5:46 PM C. Scott Ananian <[hidden email]> wrote:
`arr.slice(-1)[0]` does what you want, I think.
 --scott
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Negative indexes

Logan Smyth
Felipe, this has been discussed in the other thread that was just linked: https://esdiscuss.org/topic/javascript-language-feature-idea. `arr[-1]` is not a workable solution because it could break existing code.

On Mon, Feb 1, 2016 at 4:43 PM, Felipe Nascimento de Moura <[hidden email]> wrote:
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.



On Mon, Feb 1, 2016 at 5:46 PM C. Scott Ananian <[hidden email]> wrote:
`arr.slice(-1)[0]` does what you want, I think.
 --scott
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Negative indexes

Felipe Nascimento de Moura
hm...yep...you are right!

On Mon, Feb 1, 2016 at 10:51 PM Logan Smyth <[hidden email]> wrote:
Felipe, this has been discussed in the other thread that was just linked: https://esdiscuss.org/topic/javascript-language-feature-idea. `arr[-1]` is not a workable solution because it could break existing code.

On Mon, Feb 1, 2016 at 4:43 PM, Felipe Nascimento de Moura <[hidden email]> wrote:
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.



On Mon, Feb 1, 2016 at 5:46 PM C. Scott Ananian <[hidden email]> wrote:
`arr.slice(-1)[0]` does what you want, I think.
 --scott
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss