Test case details

Preparation Code

const set = new Set(); set.add(new Date()); for (let i = 0; i < 100000; i++) { set.add(Math.random()); } set.add(new Date()); for (let i = 0; i < 100000; i++) { set.add(i*10); } set.add(new Date()); for (let i = 0; i < 100000; i++) { set.add(performance.now()); } set.add(new Date()); const alph = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; const randChar = () => alph[Math.floor(Math.random()*alph.length)]; const randChars = (len = 6) => Array(len).fill(0).map(a => randChar()).join(""); for (let i = 0; i < 100000; i++) { set.add(randChars(Math.ceil(Math.random()*100))); } function getFirstItemOfSet(set) { for(let item of set) { if(item) { return item; } } return undefined; }

Test cases

Test #1

const first = [...set][0];

Test #2

const first = set.keys().next().value;

Test #3

const [first] = set;

Test #4

const first = getFirstItemOfSet(set);