Skip to main content

toJSON

method URL.prototype.toJSON
Jump to headingURL.prototype.toJSON(): string

The toJSON() method on the URL object returns the serialized URL. The value returned is equivalent to that of href and toString.

This method is automatically called when an URL object is serialized with JSON.stringify().

const myURLs = [
  new URL('https://www.example.com'),
  new URL('https://test.example.org'),
];
console.log(JSON.stringify(myURLs));
// Prints ["https://www.example.com/","https://test.example.org/"]

Return Type Jump to heading

string
Back to top