Destructuring arrays using the rest parameter

if anybody is familiar with destructuring an array’s challenge, the moderators of the forum if they can help, can you please explain this little paragraph in the challenge that I can not put my head around:
“the rest element only works correctly as the last variable in the list. As in, you can not use the rest parameter to CATCH A SUBARRAY THAT LEAVES OUT THE LAST ELEMENT OF THE ORIGINAL ARRAY” end of the quote.
i can not imagine what this means, I tried to experiment on the rest parameter with arrays and nested ones too, the rest parameter works no matter what I leave in the original array, what do they mean by that upper case phrase I highlighted up in the quote(again it’s from the curriculum challenges of es6 section)?
link to the challenge:https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements
thank you.

Do you have a duplicate account:

yes it’s me sorry I just needed an answer before I move on to the next challenge, that was my work account.
sorry.

i wake up and go early to work, so i used my work account, to keep up with the studying and all.

Multiple accounts confuses the forum software. The forum just marked your reply with the @markson account as spam, for example. I went ahead and closed that duplicate account so the forum isn’t as confused.


On to your question, that sentence is saying that

let [a, b, ...arr] = [1, 2, 3, 4, 5, 6, 7];

is fine, but you can’t do

let [a, b, ...arr, c] = [1, 2, 3, 4, 5, 6, 7];

because this would be invalid syntax that is not supported by the rest syntax.

perfect, thanx and sorry for the confusion.

1 Like

No worries. Glad the explanation helped!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.