transpose
The value at row i, column j of the input is at row j, column i of the result. A new matrix is built; the input is not modified.
The input must be a matrix with uniform row lengths — the rule isConsistent2DArray states — since a ragged input has no transpose. Anything else throws a plain Error.
In a spreadsheet this is the conversion between the two shapes a range comes in: a column read as one row per cell, and a single row holding the same values.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The matrix to transpose. Left untouched. |
Returns
Array<Array<unknown>> — a new matrix with the rows and columns swapped. Element types are preserved.
Throws
Exception | Condition |
|---|---|
| The input is not a matrix, or its rows differ in length. |
Examples
Rows become columns
Writing a list down a column
setValues wants one row per cell to fill a column, and a flat list is not that shape.
Invalid input
See also
isConsistent2DArray— the shapetransposerequires.chunk— reshapes a flat array into rows.
Source
This documentation was generated with AI (Claude) from the library's source code.