ES6: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  "use strict";
  // change code below this line
  arr = list; // change this
  // 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];

MY QUESTION :
In the above code, why does this solution work :-

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

While this doesn’t :-

[,,...arr] = list;
1 Like

variable_type variable_name = variable_value

You’re missing the first of those in your second example.

I thought that the variable type would be assigned const automatically because list was also a const.
Thanks though!

1 Like