basicly if variable is [3,4,4,5,6]
Then firstElement is equel to 3.
secondElement is equal to 4.
And the rest of your elements in the array are assigned to the variable ‘theRest’.
Hope this helps.
This was helpful but I am still misunderstanding something because I haven’t gotten the correct answer. When I type const [, ,c,d,e,.arr] outside of the function and type console.log(c,d,e) I get 3,4,5 but if I use the information from the hint and place it inside the function I do not get the correct answer. What am I not seeing?
You are only meant to skip the first two elements. You are doing that using empty elements [, ,] the rest of the identifiers you added c,d,e will remove three more elements which you are not supposed to do.
Use a destructuring assignment with the rest syntax to emulate the behavior of Array.prototype.slice(). removeFirstTwo() should return a sub-array of the original array list with the first two elements omitted.
Ok, what are you supposed to return? It will not be the original list since destructuring does not mutate (change) the original array.
These are the instructions. I can’t changed (list) or use array.prototype.slice().
Use a destructuring assignment with the rest syntax to emulate the behavior of Array.prototype.slice() . removeFirstTwo() should return a sub-array of the original array list with the first two elements omitted.
I just showed you the instructions. I want you to answer my question in your own words. You can’t accomplish a task if you can’t articulate what it wants!
This the paragraph provided. I think it means to removeFirstTwo(list) hast to equal 3,4,5. I used the destructuring to get to have an output of 345 but it not = removeFirstTwo(list). I am not allowed to change list or use slice.
In some situations involving array destructuring, we might want to collect the rest of the elements into a separate array.
The result is similar to Array.prototype.slice(), as shown below:
The console would display the values 1, 2 and [3, 4, 5, 7].
Variables a and b take the first and second values from the array. After that, because of the rest syntax presence, arr gets the rest of the values in the form of an array. The rest element only works correctly as the last variable in the list. As in, you cannot use the rest syntax to catch a subarray that leaves out the last element of the original array.
Use a destructuring assignment with the rest syntax to emulate the behavior of Array.prototype.slice(). removeFirstTwo() should return a sub-array of the original array list with the first two elements omitted.
you can’t change the original list but you can create a new variable which contains the contents of the original list mines the first two elements.
const [,,theRest]
if equel to the original list then theRest will contain all the list elements with the first two omitted. Now return this variable instead of the original list which was not modified.