0

When I try to delete a javascript Map key, the key seems to be deleted, and to stay at the same time. Array assigns ( e.g. map[a] = b ) are never used, and I totally don't know why it occurs : enter image description here

For sensible datas reason, the keys (that are strings) are replaced by colors.

Lines:
1 : map before deleting the user
2 : user to delete (in the for loop)
3 : this._members.get(userId)
4 : this._members.delete(userId) => it works
5 : map after deleting the user

Code :

console.dir(this._members);
for (const userId of removedUserIds) {
    console.dir(userId);
    console.dir(this._members.get(userId));
    console.dir(this._members.delete(userId));
}
console.dir(this._members);
Kaki In
  • 29
  • 9
  • 1
    Notice the second log starts with `Map(1)`. This means that *at the time when it was logged), there was one item in it. Between that point in time and when you expanded it in the console, a new entry was added. [Is Chrome’s JavaScript console lazy about evaluating objects?](https://stackoverflow.com/q/4057440) – VLAZ Jul 28 '22 at 10:43
  • Ok, thanks a lot. Cannot you make an answer? I think it resolves my problem. – Kaki In Jul 28 '22 at 10:53

0 Answers0