const rect = new DOMRectReadOnly(10, 20, 100, 50);
const json = rect.toJSON();
console.log(json);
// { x: 10, y: 20, width: 100, height: 50, top: 20, right: 110, bottom: 70, left: 10 }
console.log(typeof json); // "object"DOMRectReadOnly: toJSON() method / notebook
DOMRectReadOnly: toJSON() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const rectJSON = JSON.stringify(rect);
console.log(rectJSON);