Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Array.slice with negative numbers safe?

Tags:

javascript

I remember reading years ago that passing negative numbers as the 2nd argument to some of the functions with this syntax (slice, substr, etc) was only supported in some browsers, but I can't find the reference.

Just wondering if anyone knows if ary.slice(0, -1) specifically is safe across all browsers.

like image 762
Nobody Avatar asked Jan 20 '17 22:01

Nobody


1 Answers

Using a negative number for either the start or end value (or both) is safe and will select from the end of the array. It is supported across IE, FF, Chrome, Safari, and Opera.

like image 118
tonythewest Avatar answered Sep 24 '22 03:09

tonythewest