Hello, I’m using destructuring with the rest parameter in order to return an array excluding the first two elements of the original array. The error I am getting is that variable (a) is undefined. Can someone lead me on the proper path as to how to define variable (a) and (b) because in the course reading I see they structured the code the same way I am writing it so I figured to just try to mirror the same structure if that makes sense.
//My Code
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
const arr = [a, b, ...list];
return arr; //<---- Getting error because (a) is undefined
}
const arr = removeFirstTwo(source);
//----------------------------------------------------------------------------------------------------------
//course example
const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
console.log(a, b);
console.log(arr);
//The console would display the values 1, 2 and [3, 4, 5, 7].
//--------------------------------------------------------------------------------------------------------
//Since my first attempt said that Variable (a) was undefined I tried this below but it //does not work either.
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
let a = source[0];
let b = source[1];
let arr = [a, b, ...list];
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/91.0.4472.124 Safari/537.36
Challenge: Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements
Link to the challenge: