i want to remove the first array element, without modified the original (immutable),
something like this:
JavaScript
x
8
1
function getArray(): number[] {
2
return [1, 2, 3, 4, 5];
3
}
4
function getAnother(): number[] {
5
const [first, rest] = getArray();
6
return rest;
7
}
8
the code works, but the typescript check complained:
JavaScript
1
2
1
'first' is assigned a value but never used @typescript-eslint/no-unused-vars
2
Is there the elegant/better way to do somilar to getAnother()
?
Advertisement
Answer
You can ignore an element with a comma.
JavaScript
1
2
1
const [, rest] = getArray();
2
Array#slice
can also be used in this case.
JavaScript
1
2
1
const rest = getArray().slice(1);
2