You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test values for equivalence, `Map` uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). It is roughly the same as the strict equality `===`, but the difference is that `NaN` is considered equal to `NaN`. So `NaN` can be used as the key as well.
79
+
To test values for equivalence, `Map` uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). It is roughly the same as strict equality `===`, but the difference is that `NaN` is considered equal to `NaN`. So `NaN` can be used as the key as well.
80
80
81
81
This algorithm can't be changed or customized.
82
82
```
@@ -106,7 +106,7 @@ let map = new Map([
106
106
]);
107
107
```
108
108
109
-
There is a built-in method [Object.entries(obj)](mdn:js/Object/entries) that returns the array of key/value pairs for an object exactly in that format.
109
+
There is a built-in method [Object.entries(obj)](mdn:js/Object/entries) that returns an array of key/value pairs for an object exactly in that format.
110
110
111
111
So we can initialize a map from an object like this:
Note the funny thing. The `forEach` function in the `Set` has 3 arguments: a value, then *again a value*, and then the target object. Indeed, the same value appears in the arguments twice.
225
225
226
-
That's made for compatibility with `Map` where `forEach` has three arguments.
226
+
That's for compatibility with `Map` where `forEach` has three arguments.
227
227
228
-
The same methods as `Map` has for iterators are also supported:
228
+
The same methods `Map` has for iterators are also supported:
229
229
230
230
- `set.keys()` -- returns an iterable object for values,
231
231
- `set.values()` -- same as `set.keys`, for compatibility with `Map`,
That's useful for situations when we have a main storage for the objects somewhere and need to keep additional information that is only relevant while the object lives.
332
332
333
-
Let's see an example.
333
+
Let's look at an example.
334
334
335
-
For instance, we have a code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store his visit count anymore.
335
+
For instance, we have code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store his visit count anymore.
336
336
337
337
One way would be to keep track of leaving users and clean up the storage manually:
0 commit comments