We have an array [1,2,3]
and we want to remove [1,2]
so that we end up with [3]
.
Approach
const arr = [1, 2, 3];
const three = arr.slice(2);
Thus when only one argument (2
) is passed to slice as shown, it removes indexes up to that number. In this case it removes the items with indexes 0
and 1
and returns the resulting array [3]
.