Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

I am still havinf problems with it.

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  "use strict";
  // change code below this line
const [a,b,...arr] = source;

const [a,b] = list;

  // change code above this line
  return arr;
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];

So, in that first line, you are referring to a variable that your function should know nothing about. As far as your function is concerned, source does not exist. The only point of contact with the world outside your function should be the parameter you get in (list), and what you send out (in your return arr).

In the second line I’ve quoted, you set a and b to the first two members of list, which is great, but this one is missing the ...arr to get the rest of the list.

Use one line. One const [/*something something something*/] = list; - just one line will do everything you’re looking for. And nobody is going to simply tell you, you’ll learn more by trying to figure why it’s not working.

1 Like

I am thankful with their help. Thank you.