toObject

Returns a new plain object form of the matrix, keys ascending and rows copied.

import { Matrix } from "@teakit/matrix";

const input = { b: [1, 2], a: [3] };
const out = Matrix.toObject(input);
// { a: [3], b: [1, 2] }  (keys ascending)
out !== input; // true
out.a !== input.a; // true (rows copied)

// Cell values are not deep-copied.
const cell = { v: 1 };
Matrix.toObject({ a: [cell] }).a[0] === cell; // true

API Reference

Signature

Matrix.toObject<T, TKey extends string>(
  matrix: Matrix<T, TKey>,
): Matrix<T, TKey>;

Parameters

ParameterTypeRequiredNotes
matrixMatrix<T, TKey>YesA value already known to be a matrix.

Returns

A new plain object with keys ascending and rows copied; cell values share references.

Throws

Does not throw.

Agent Contract

FieldValue
Kindstatic conversion
Canonical nametoObject
AliasesNone
Mutates inputsNo
ReturnsMatrix<T, TKey>

Agent Notes

  • For serialization use toJSON; the package provides no Matrix.toString / Matrix.valueOf.
  • For unknown/external input, validate with from first.