I want to have something like Java's linkedHashMap, where the elements in it are in insertion order, and I can extract the first inserted and/or also remove it from the map, as I need. I know that in js, by default, maps store by insertion order but I can't figure out how to both extract the value & key of the first inserted, and then remove that item(the pair) from the map. Sort of like removing the first from a queue. Given that js Maps are defaulted to be stored in insertion order, I figure this should be possible, but I don't know how to do it.
for context, I'm doing this to improve the efficiency of a leetcode question, that uses the sliding window pattern.
Well if all you want is to remove the first inserted key-value pair from a Map, then you could simply do:
map.delete(map.keys().next().value)
Depending on the requirements of the full problem you are trying to solve of course, you could optimize this by storing the keys iterator in a variable or something of the like.