Based on your comment, you're buildng some kind of a LRU cache. You might consider a better data structure that just a Map. For example,
cache = { deque: Array, index: Map, offset: Int }
When you put element in the cache, you append it to the deque and store its position + offset in the index:
class Cache...
put(obj) {
this.deque.push(obj)
pos = this.deque.length - 1
this.index.set(key(obj), pos + this.offset)
}
When getting element, check it its index of positive
get(obj) {
pos = this.index.get(key(obj)) - this.offset
if pos >= 0
return this.deque[pos]
// cache miss....
Now, cleaning up the cache won't involve any loops
clear(count) {
this.deque.splice(0, count)
this.offset += count
}
On a general note, if you want something to be re-created, but need a persistent pointer to it in the same time, you can just wrap the private object into a public one and proxy (some of) private's methods:
class Cache
this._map = new Map() // feel free to recreate this when needed
get(x) { return this._map.get(x) }
set(x, y) { return this._map.set(x, y) }
myCache = new Cache() // this can be saved somewhere else