To get subarray from array with JavaScript, we use the slice
method.
For instance, we write
const ar = [1, 2, 3, 4, 5];
const ar2 = ar.slice(1, 4);
console.log(ar2);
to call ar.slice
with 1 and 4 to return a new array with the entries in ar
from index 1 to 3.