Use Destructuring Assignment with the Rest Operator - Instead of taking first two elements, how woyuld you get the last two? Or any x amount in the middle?

Use Destructuring Assignment with the Rest Operator - Instead of taking first two elements, how woyuld you get the last two? Or any x amount in the middle?
0

#1

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-operator-to-reassign-array-elements/

Challenge as above

Using

const [a,b, ...arr] = list;

allows the input array to have it’s first two elements ‘‘taken out’’ and the remaining elements given as arr.

I wanted to play around with this - how would one achieve the opposite, that is, I want the last two elements of any array taken out and all elements before that to be it’s own array.

I thought this would be sufficent:

const[...arr ,a,b] = list;

Or say, you wanted to take out the first two elements and the last two elements but evertyhing in the middle is its own array like:


 const [a,b, ...arr , x , y] = list;

Of course, thesedoesn’t work which is why I’m asking now, ha.