How to get the second element of a set in JavaScript

2 Answers

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

console.log(second_element); 

 
 
 
  
/*
run:
  
"c"
  
*/

 



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

console.log(second_element); 

 
 
 
  
/*
run:
  
"c"
  
*/

 



answered Jul 10, 2022 by avibootz
...