How to convert object to JSON in JavaScript

1 Answer

0 votes
const obj = {
  id: 383912,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};
 
const sJSON = JSON.stringify(obj);
 
console.log(sJSON);
 
 
   
     
     
/*
run:
     
"{"id":383912,"name":"Albus Dumbledore","academicrank":"Professor"}"
     
*/

 



answered Jan 27, 2021 by avibootz
edited Feb 25, 2022 by avibootz

Related questions

1 answer 152 views
1 answer 146 views
1 answer 173 views
1 answer 171 views
1 answer 196 views
2 answers 232 views
1 answer 104 views
...