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
Copy file name to clipboardExpand all lines: 1-js/05-data-types/07-map-set/article.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,12 @@ alert( map.size ); // 3
41
41
42
42
As we can see, unlike objects, keys are not converted to strings. Any type of key is possible.
43
43
44
+
```smart header="`map[key]` isn't the right way to use a `Map`"
45
+
Although `map[key]` also works, e.g. we can set `map[key] = 2`, this is treating `map` as a plain JavaScript object, so it implies all corresponding limitations (no object keys and so on).
46
+
47
+
So we should use `map` methods: `set`, `get` and so on.
In the replacement string `$&` means the match itself, that is, we replace `pattern:<body.*>` Is replaced by itself plus`<h1>Hello</h1>`.
14
+
In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:<body.*>`. It gets replaced by itself plus `<h1>Hello</h1>`.
14
15
15
-
An alternative is to use retrospective validation:
Such a regular expression at each position will check if `pattern:<body.*>`does not go directly in front of it. If yes, a match is found. But the tag `pattern:<body.*>` does not coincide, it only participates in the verification. And there are no other characters after checking in it, so the match text will be empty.
25
+
As you can see, there's only lookbehind part in this regexp.
26
+
27
+
It works like this:
28
+
- At every position in the text.
29
+
- Check if it's preceeded by `pattern:<body.*>`.
30
+
- If it's so then we have the match.
31
+
32
+
The tag `pattern:<body.*>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:<body.*>`.
25
33
26
-
This replaces the "empty line", followed by `pattern:<body.*>` With`<h1>Hello</h1>`. Which, exactly, is the insertion of this line after `<body>`.
34
+
So we replaces the "empty line", preceeded by `pattern:<body.*>`, with`<h1>Hello</h1>`. That's the insertion after `<body>`.
27
35
28
-
P.S. The flags: `pattern:/<body.*>/si`, will not interfere with this regular expression, so that a line break appears in the "dot" (a tag can span several lines), and also that the tags are in a different register of the `match:<BODY>`type, too.
36
+
P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also useful: `pattern:/<body.*>/si`. The `pattern:s` flag makes the dot`pattern:.` match a newline character, and `pattern:i` flag makes `pattern:<body>` also match `match:<BODY>`case-insensitively.
0 commit comments