Implementation of a shift operation for Set in JavaScript that emulates the one for arrays I discovered that the JavaScript sets are ordered but don't offer a method to take the first element out of the set. For the arrays this operation exists and it's called shift.

A very basic implementation can be written in this way:

function shiftSet(s) {
    let res;
    for (let v of s) {
        res= v;
        break;
    }
    s.delete(res);
    return res;
}


Do you see a better way to write it?
Another way to do it is via the iterator function. 

function shifySet(set) {
    const first = set[Symbol.iterator]().next().value;
    set.delete(first);
    return first;
}


I was going to check if there was an item, but it seams pointless. Works the same as your function shifts the first entry, returning it, or undefined if not found.

I would make a slight change to your version

function shiftSet(set) {
    for (const res of set) {
        set.delete(res);
        return res
    }
}