DEV Community

Discussion on: Two Ways to Rotate an Array in JavaScript

Collapse
alekseiberezkin profile image
Aleksei Berezkin

Or, to avoid arr concatenation if it can be large,

const rotateArray = (arr, k) => arr.slice(k).concat(arr.slice(0, k));
Enter fullscreen mode Exit fullscreen mode