DOMMatrixReadOnly: toString() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The toString()
stringifier of the DOMMatrixReadOnly
interface returns the value of the matrix as a string in the form of a matrix()
or matrix3d()
CSS transform function; comma-separated lists of 6 or 16 coordinate values, prepended by "matrix(
or "matrix3d(
respectively, appended by )"
.
For a 2D matrix, the elements a
through f
are listed, for a total of six values and the form matrix(a, b, c, d, e, f)
. See the matrix()
CSS function for details on this syntax.
For a 3D matrix, the returned string contains all 16 elements and takes the form matrix3d(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44)
. See the CSS matrix3d()
function for details on the 3D notation's syntax.
Syntax
DOMMatrixReadOnly.toString()
Parameters
None.
Return value
A string; the values of the list separated by commas, within matrix()
or matrix3d()
function syntax.
Examples
const matrix = new DOMMatrixReadOnly();
console.log(matrix.translate(20, 30).toString()); // matrix(1, 0, 0, 1, 20, 30)
console.log(matrix.translate(30, 40, 50).toString()); // matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 30, 40, 50, 1)
console.log(matrix.skewY(15).skewX(5).rotate(3).translate(20, 50).toString());
// matrix(1.003, 0.321, 0.035, 1.01, 21.816, 56.824)
console.log(
matrix.skewY(15).skewX(5).rotate(3).translate(20, 50, 60).toString(),
);
// matrix3d(1.003, 0.321, 0, 0, 0.0350, 1.008, 0, 0, 0, 0, 1, 0, 21.816, 56.824, 60, 1)
Specifications
No specification found
No specification data found for api.DOMMatrixReadOnly.toString
.
Check for problems with this page or contribute a missing spec_url
to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
Browser compatibility
BCD tables only load in the browser