Rotate Array Left

Rotate array elements to the left by a specified number of positions, wrapping elements around.

Code

General
const k = n % arr.length;
[...arr.slice(k), ...arr.slice(0, k)];

Parameters

Array to rotate

Positions to rotate

Browser·fetch() may be limited by CORS

More JavaScript Snippets