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
When a `Map` is created, we can pass an array (or another iterable) with key/value pairs for initialization, like this:
151
+
Quando um `Map` é criado, podemos passar um array (ou outro iterável) com pares chave/valor para inicialização, como este:
152
152
153
153
```js run
154
-
// array of [key, value] pairs
154
+
// array de pares [chave, valor]
155
155
let map = new Map([
156
156
['1', 'str1'],
157
157
[1, 'num1'],
@@ -161,9 +161,9 @@ let map = new Map([
161
161
alert( map.get('1') ); // str1
162
162
```
163
163
164
-
If we have a plain object, and we'd like to create a `Map` from it, then we can use built-in method [Object.entries(obj)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) that returns an array of key/value pairs for an object exactly in that format.
164
+
Se tivermos um objeto simples e gostaríamos de criar um `Map` a partir dele, podemos usar o método embutido [Object.entries(obj)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries), que retorna um array de pares chave/valor para um objeto exatamente nesse formato.
165
165
166
-
So we can create a map from an object like this:
166
+
Portanto, podemos criar um mapa a partir de um objeto da seguinte forma:
167
167
168
168
```js run
169
169
let obj = {
@@ -178,8 +178,7 @@ let map = new Map(Object.entries(obj));
178
178
alert( map.get('name') ); // John
179
179
```
180
180
181
-
Here, `Object.entries` returns the array of key/value pairs: `[ ["name","John"], ["age", 30] ]`. That's what `Map` needs.
182
-
181
+
Aqui, `Object.entries` retorna o array de pares chave/valor: `[ ["name","John"], ["age", 30] ]`. Isso é o que o `Map` precisa.
0 commit comments