ES6Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

I understand what the problem is asking just don’t know how to go about it . I wanted to use rest parameter but not sure how i would even go about it without changing the top line but thats not what its asking. I guess another way i thought about it is to destructure assignment maybe assigning to a different variable then use rest param on the rest IDK MY head hurts :rofl: I’m gonna take a nap and come back to see what you guys suggest. I do feel like there is probably a extremely simple way to do this, and once i figure it out i will feel dumb for thinking too much about this
Your code so far


const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
// Only change code below this line
const arr = list; // Change this line
// Only change code above this line
return arr;
}
const arr = removeFirstTwo(source);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

Link to the challenge:

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  // Only change code below this line
  const [one, two, ...arr] = list; // Change this line
  // Only change code above this line
  return arr;
}
const arr = removeFirstTwo(source);

this is how you go about it.

The important thing about using the rest param is that it must be the last thing used in the assignment such as:

const [one, two, ...everythingElse] = [1,2,3,4,5,6,7];
console.log(one) //1
console.log(two) //2
console.log(everythingElse) //[3,4,5,6,7];
console.log(Array.isArray(everythingElse)) //true

destructuring can be used in various ways, and it can get a bit confusing if you are trying to destructure nested elements, but this should give you an alright idea as how you would use it on a basic level.

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