Identifies the type of array elements
The array or array-like object to rotate
Number of positions to rotate. Positive = right, negative = left
A new array with elements rotated
arrRotate([1, 2, 3, 4, 5], 2); // [3, 4, 5, 1, 2]
arrRotate([1, 2, 3, 4, 5], -2); // [4, 5, 1, 2, 3]
arrRotate([1, 2, 3], 0); // [1, 2, 3]
arrRotate([1, 2, 3], 3); // [1, 2, 3] (full rotation)
arrRotate([1, 2, 3], 5); // [3, 1, 2] (wraps around)
arrRotate([1, 2, 3], -5); // [2, 3, 1] (wraps around)
arrRotate([], 3); // []
// Array-like objects
arrRotate({ length: 3, 0: "a", 1: "b", 2: "c" }, 1); // ["b", "c", "a"]
The arrRotate() method returns a new array with elements rotated by the specified number of positions. Positive values rotate left (elements shift forward), negative values rotate right (elements shift backward). The original array is not modified.