What is sub-array, I am unable to understand the example and defination

Tell us what’s happening:
What is sub-array? I am lost in the question of where it is telling

you cannot use the rest parameter to catch a subarray that leaves out the last element of the original array.

and question part

so that arr is a sub-array of the original array source with the first two elements omitted.

As I am not too sure about what is being asked I did the following

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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

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

Link to the challenge:

It is asking for rest, not spread. So what you have needs to be on the left-hand side (with arr not list)


Not sure why the text is talking about rest parameter though. As clearly by the name that would involve parameters. MDN calls it a rest property when …rest is used with a destructuring assignment.

I think the challenge text should be updated.

Edit: Issue

You can do const [,,....subArr] = arr but not const [...subArr,] = arr

edit: sorry I had to remember how to do it lol.

  1. [a,b,c,d,e,f] is an array b,c,d or a,b,c or d.e.f are sub-array ( any partial of the array is sub-array)
    the key of this challenge I think should be rest parameter
    try visit this link to get idea of rest parameter
    Rest parameters - JavaScript | MDN

When you use rest parameter You take all the rest as an array
for example
var [a,b , …c] = [1,2,3,4,5]
a = 1
b = 2
c = [3,4,5] you can not take only [3,4] and left 5

Hope this will help. Happy coding

Sorry all, I am very lost.

Can we see what you have now?


The ...rest should be on the left-hand side and it should be used with the arr, not the list.

const [one, two, ...restElement] = [1, 2, 3, 4, 5];
console.log(one, two, restElement); // 1 2 [3, 4, 5]

You can use , as an empty element to skip elements.

const [,,...restElement] = [1, 2, 3, 4, 5];
console.log(restElement); // [3, 4, 5]

Thank you but I still trying to understand sub-array.

sub-array of the original array

Just means part of the original array, like a sub-section.

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