How to get a last element of ES6 Map/Set without iterations(forEach or for of) pass through a full length of the container?
Maps are iterable and ordered, but they are not arrays so they don't have any indexed access. Iterating to the final element is the best you can do. The simplest case being
Array.from(map.values()).pop();
2.1m questions
2.1m answers
60 comments
57.0k users