Firefox Tomorrow

web api instance method

DOMRectReadOnly: toJSON() method

View on MDN ↗

Available in workers

The DOMRectReadOnly method toJSON() returns a JSON representation of the DOMRectReadOnly object.

Syntax

toJSON()

Parameters

None.

Return value

A new object whose properties are set to the values in the DOMRectReadOnly on which the method was called.

Examples

This example creates a DOMRectReadOnly that represents a rectangle at position (10, 20) with a width of 100 and a height of 50. It then calls toJSON() to obtain a JSON representation of the rectangle.

const rect = new DOMRectReadOnly(10, 20, 100, 50);

const rectJSON = rect.toJSON();
console.log(rectJSON);
// Output: { x: 10, y: 20, width: 100, height: 50, top: 20, right: 110, bottom: 70, left: 10 }

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.