DuckDucking turned up this by Ken. Surprisingly, it's even more concise and complete than Nikita's answer. It retrieves column and row lengths implicitly within the guts of map()
.
function transpose(a) {
return Object.keys(a[0]).map(function(c) {
return a.map(function(r) { return r[c]; });
});
}
console.log(transpose([
[1,2,3],
[4,5,6],
[7,8,9]
]));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…