How to convert a set to JSON in TypeScript

2 Answers

0 votes
const st = new Set(['typescript', 'javascript', 'node.js', 'php']);
  
const json = JSON.stringify(Array.from(st));

console.log(json); 
  
  
  
/*
run:
  
"["typescript","javascript","node.js","php"]" 
  
*/

 



answered May 19, 2022 by avibootz
0 votes
const st = new Set(['typescript', 'javascript', 'node.js', 'php']);
  
const json = JSON.stringify([...st]);

console.log(json); 
  
  
  
/*
run:
  
"["typescript","javascript","node.js","php"]" 
  
*/

 



answered May 19, 2022 by avibootz
...