How to get the first element of a set in TypeScript

2 Answers

0 votes
const st = new Set(['typescript', 'javascript', 'node.js', 'c++']);
  
const [first_element] = st;
 
console.log(first_element); 
 
  
  
  
   
/*
run:
   
"typescript" 
   
*/

 



answered Jul 10, 2022 by avibootz
0 votes
const st = new Set(['typescript', 'javascript', 'node.js', 'c++']);
  
const first_element = [...st][0];
 
console.log(first_element); 
 
  
  
  
   
/*
run:
   
"typescript" 
   
*/

 



answered Jul 10, 2022 by avibootz

Related questions

1 answer 202 views
2 answers 253 views
1 answer 261 views
1 answer 166 views
1 answer 206 views
...