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
"Como `visitsCountObj` é um objeto, ele converte todas as chaves de `Object`, como `john` e `ben` acima, para a mesma string `"[object Object]"`. Definitivamente, não é o que queremos."
85
+
Como `visitsCountObj` é um objeto, ele converte todas as chaves de `Object`, como `john` e `ben` acima, para a mesma string `"[object Object]"`. Definitivamente, não é o que queremos.
86
86
87
87
```smart header="Como o `Map` compara chaves"
88
88
Para testar as chaves quanto à equivalência, o `Map` utiliza o algoritmo [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). Ele é essencialmente o mesmo que a igualdade estrita `===`, mas a diferença é que `NaN` é considerado igual a `NaN`. Portanto, `NaN` pode ser usado como chave também.
@@ -100,15 +100,15 @@ map.set('1', 'str1')
100
100
```
101
101
````
102
102
103
-
## Iteration over Map
103
+
## Iteração sobre o Mapa
104
104
105
-
For looping over a `map`, there are 3 methods:
105
+
Para fazer um loop em um `map`, existem 3 métodos:
106
106
107
-
- [`map.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) -- returns an iterable for keys,
108
-
- [`map.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) -- returns an iterable for values,
109
-
- [`map.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) -- returns an iterable for entries `[key, value]`, it's used by default in `for..of`.
107
+
- [`map.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) -- retorna um iterável para chaves,
108
+
- [`map.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) -- retorna um iterável para valores,
109
+
- [`map.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) -- retorna um iterável para entradas `[chave, valor]`, é usado por padrão em `for..of`.
110
110
111
-
For instance:
111
+
Por exemplo:
112
112
113
113
```js run
114
114
let recipeMap = new Map([
@@ -117,30 +117,30 @@ let recipeMap = new Map([
117
117
['onion', 50]
118
118
]);
119
119
120
-
// iterate over keys (vegetables)
120
+
// itera sobre as chaves (vegetais)
121
121
for (let vegetable of recipeMap.keys()) {
122
122
alert(vegetable); // cucumber, tomatoes, onion
123
123
}
124
124
125
-
// iterate over values (amounts)
125
+
// itera sobre os valores (quantidades)
126
126
for (let amount of recipeMap.values()) {
127
127
alert(amount); // 500, 350, 50
128
128
}
129
129
130
-
// iterate over [key, value] entries
131
-
for (let entry of recipeMap) { // the same as of recipeMap.entries()
132
-
alert(entry); // cucumber,500 (and so on)
130
+
// itera sobre as entradas [chave, valor]
131
+
for (let entry of recipeMap) { // o mesmo que recipeMap.entries()
132
+
alert(entry); // cucumber,500 (e assim por diante)
133
133
}
134
134
```
135
135
136
-
```smart header="The insertion order is used"
137
-
The iteration goes in the same order as the values were inserted. `Map` preserves this order, unlike a regular `Object`.
136
+
```smart header="A ordem de inserção é usada."
137
+
A iteração segue a mesma ordem em que os valores foram inseridos. O `Map` preserva essa ordem, ao contrário de um objeto normal.
138
138
```
139
139
140
-
Besides that, `Map` has a built-in `forEach` method, similar to `Array`:
140
+
Além disso, o `Map` possui um método embutido chamado `forEach`, semelhante ao `Array`:
0 commit comments