hey guys, is there anyway using es6 destructuring so I can remove the first element of args array? or using to mark the rest of them? having some difficulties with the docs.
edit: I have found a solution with slice, just wondering if possible with using destructuring too thanks.
function destroyer(arr, ...rest)
i solved the challenge, but I saw at the solutions this is also possible to use.
but just for my knowledge is it possible to do with my first example?
const args = [...arguments] const [x, arr2] = args
this gives me 2, and not the rest like I want.
just to be completely clear, this is both variants of the ... operator.
In the first line, const args = [...arguments], we have the spread version of the operator. We are “spreading” each item in arguments as a comma-separated list within the [ ].
In the second line, const [x, ...arr2] - args we have the rest operator. Here, we are capturing “the rest” of the elements in the args array.
Whether it is rest or spread is determined by which side of the assignment we find it. If on the left (variable) side, it’s rest - if on the right (expression) side, it’s spread.
The exception is an implied assignment: the parameters of a function. When we are defining parameters, we are defining the variable side of an assignment, so when we see: