0๐
โ
If Iโm understanding you correctly, you just want to remove the last elements (highest index) first?
If so, just use images.length
to get the last index:
images.splice(images.length - 1, 1); // splice off the last image
If you need to splice multiple, just subtract (1 + numberToRemove)
from images.length
:
images.splice(images.length - 4, 3); // splice off the last 3
or:
const numToRemove = 3;
images.splice(images.length - 1 - numToRemove, numToRemove);
Source:stackexchange.com