I have been attempting to convert my object person
into a JSON format.
const person = new Object();
person.firstName = 'testFirstName';
person.lastName = 'testLastName';
var myJson = JSON.stringify(person);
console.log(myJson);
console.log(typeof myJson); // Despite calling it JSON, the return type is actually string.
When I attempt to display my supposed JSON and check the type of the element (myJson
), it shows as an string
.
Can anyone provide assistance in understanding this discrepancy and suggest a better approach to achieve my goal?