while (array.length) { vector.push(...array.shift()); console.log(vector); array.map(row => vector.push(row.pop())); array.reverse().map(row => row.reverse()); }