I’m not a pro, but this is what I believe is correct:
Question 1: what is index & what is [0]:
const element = output.splice(index,1)[0];
“output” is the given array (in this case [1,2,3,4]);
in which you want to remove a number. (which is specified by the user)
The user can choose the position of this number with the “index” through the method splice.
So the index is refering to the position of the element in the array. If the index was 0, the first element sice arrays are zero based.
We can write the folowing line also as the following two lines:
const element = output.splice(index,1)[0];
const removedItem = output.splice(index,1);
const element = removedItem[0];
The first line removes 1 element in the array: output at a specific position (index).
const removedItem = output.splice(index,1) //returns an array
This method returns an array with the removed elements (in this case with only 1 element) We don’t want an array (e.g. [1] or [4]) but only the element stored in the array we can acces this element by [0], because we know it is the first one.
const element = removedItem[0];
Question 2: What is index + offset?
output.splice(index + offset, 0, element);
the .splice method doesn’t just remove items, we can also replace or insert elements.
index + offset calculates the new position (index) where you want to insert the specified element.
Hope this helps. I sometimes went back to watch a video again. Maybe it’s clever to go over the explanation video about the splice method once more.