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 209 views
2 answers 261 views
1 answer 270 views
1 answer 176 views
1 answer 213 views
...