I am trying to find a way to get a range of 5 sequential indexes from an array of indeterminate length.
My array might look like this: [0,1,2,3,4,5,6,7]
I know I can use array.slice() if I need to return something like [2,3,4,5,6], but sometimes I might need to return something like [6,7,0,1,2]
Is there a clean or built-in way to do this?
If I understood right, you need something like this:
function array_indexes(arr, keys){
let res = [];
for(let k of keys){
res.push(arr[k]);
}
return res;
}