navigator.geolocation.getCurrentPosition((position) => {
const coords = position.coords;
const json = coords.toJSON();
console.log(json); // A plain object
console.log(typeof json); // "object"
console.log(json.latitude); // Same value as coords.latitude
});GeolocationCoordinates: toJSON() method / notebook
GeolocationCoordinates: toJSON() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
console.log(JSON.stringify(coords));