How to get last record without key from HashMap?

I have HashMap with some record. I need last record without key from HashMap.

map.put("key1", 1);
map.put("key2", 2);
map.put("key3", 3);
map.put("key4", 3);
map.put("key5", 2);
map.put("key6", 2);

let map2 =
  HashMap.mapFilter<Text, Nat, Nat>(
    map,
    Text.equal,
    Text.hash,
    func (k, v) = if (v == 2) { null } else { ?(v == 3)}
);
so, for example map2 have two record
map.put("key3", 3);
map.put("key4", 3); // <= Last Record

How to get last record without key?

HashMap has no notion of insert order. Consider using a Vec for that.

@ZhenyaUsenkoā€™s map Maintains insertion order and can be used as a queue.

1 Like

In Azle you just do .entries()

Fun fact: the map mentioned above follows the pattern in V8 (the chrome engine). Iā€™m guessing that boa(the rust based js engine that I think Azel
Uses) likely borrowed from this as well.

Th e latest motoko version has puhfront, popfront, pushBack, popBack, an a few forward and backward iterators as well.

Can you provide me latest motoko link?