Rotate Tetris Piece JS

I’m working on a Tetris Challenge and dealing with a problem when rotating the piece.

Basically I have a two-dimensional array and using a for loop I’m exchanging the items in this position array, the problem is that the movement is not centered in the middle of the piece.

See a representation of the array before and after the spin:

original — after
0 1 0 0 — 0 0 0 0
1 1 1 0 — 0 1 0 0
0 0 0 0 — 1 1 0 0
0 0 0 0 — 0 1 0 0

function rotate( piece ) {
    var newPiece = [];
    for ( var y = 0; y < 4; y++ ) {
        newPiece[ y ] = [];
        for ( var x = 0; x < 4; x++ ) {
            newPiece[ y ][ x ] = piece[ 3 - x ][ y ];
        }
    }

    return newPiece;
}

Any insights that might help me with this?
Thanks!!