You can use a small library that I wrote to support 2D mesh operations ( https://github.com/klattiation/gridl ). It also supports rotation.
const arr = [ [1, 2, 3], [4, 5, 6], ]; const rotatedArray = gridl(arr).rotate(1).data(); // rotatedArray would look like this: // [ // [4, 1], // [5, 2], // [6, 3], // ]
You can also rotate quite easily in other directions:
gridl(data).rotate(1); // rotates 90 degrees gridl(data).rotate(2); // rotates 180 degrees gridl(data).rotate(3); // rotates 270 degrees gridl(data).rotate(-1); // rotates -90 degrees gridl(data).rotate(-2); // rotates -180 degrees gridl(data).rotate(-3); // rotates -270 degrees
source share