Get first item of set - small set

Benchmark created on


Description

On a set containing 5 strings, get the first item in the set.

Setup

const set = new Set(['a', 'b', 'c', 'd', 'e']);

function getFirstItemOfSet(set) {
  for(let item of set) {
    if(item) {
       return item;
    }   
  }
  return undefined;
}

Test runner

Ready to run.

Testing in
TestOps/sec
spread
const first = [...set][0];
ready
iterator on keys
const first = set.keys().next().value;
ready
destructuring
const [first] = set;
ready
getFirstItemOfSet
const first = getFirstItemOfSet(set);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.