Then we can call the
pop method on the returned array to return the last entry inserted into the set.
For instance, we can write:
const a = new Set([1, 2, 3]); a.add(10); const lastValue = [...a].pop(); console.log(lastValue)
We create a new set with the
Then we call
add to add a new entry into the set.
Next, we spread
a set into an array and then call
pop to return the last element from the set and remove that entry from the array.
The returned item is assigned to
Therefore, from the console log, we see that
lastValue is 10.