Need to remove the last few elements from an array? Try using negative indices with the Array.slice method
When you pass in a negative number for the start or end argument to slice, the index is computed by counting backwards from the end of the array. arr.slice(-3) for example starts the slice 3 elements back from the end of the array.
You can also use negative indices for the end argument to slice. arr.slice(0, -1) for example will slice from the start of the array (0) to 1 element before the end of the array (-1)
Whenever you see a negative number in a slice call, just remember that it means the index is determined by going backwards that many elements from the end of the array
#javascript #programming #coding