Get the last 2 items of an Array with Javascripts Slice | Task

Ole Ersoy
Aug - 14  -  1 min

Scenario

We have an array [1,2,3] and we want get the last 2 items on it, or [2,3].

Approach

const arr: number[] = [1, 2, 3];
const lasttwo = arr.slice(-2);

Demo