How to get the first element of a set in JavaScript

2 Answers

0 votes
const st = new Set(['javascript', 'typescript', 'node.js', 'c++']);
 
const [first_element] = st;

console.log(first_element); 

 
 
 
  
/*
run:
  
"javascript"
  
*/

 



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

console.log(first_element); 

 
 
 
  
/*
run:
  
"javascript"
  
*/

 



answered Jul 10, 2022 by avibootz

Related questions

...